UWP - Softwarebitmap for Stream

Asked

Viewed 50 times

0

Eai personal,

I’m using MediaFrameReader to capture the frames of a USB camera in a UWP application, the event return FrameArrived returns me an object of type Softwarebitmap, having this frame I check if there is human face using FaceDetector, by detecting these faces I intend to use the SDK of the Faceid to check if this face is registered, however the SDK requires me to send an image in Stream state, as I can do this conversion?

Thank you very much!

2 answers

1


You can choose to use Bitmapdecoder, as in the example:

var stream = new InMemoryRandomAccessStream();
ImageEncodingProperties properties = ImageEncodingProperties.CreateJpeg();
await _mediaCapture.CapturePhotoToStreamAsync(properties, stream);
var decoder = await BitmapDecoder.CreateAsync(stream);
SoftwareBitmap sfbmp = await decoder.GetSoftwareBitmapAsync();
  • The first code is not possible, because I could not use Image in UWP, but the Second and third Gave me the necessary light to execute the code, updated as an Answer! Thanks a Lot, I Lost 2 days Looking for this!

  • @Repinheiro I just updated the Answer, I’m Glad it worked.

1

Conversion:

        SoftwareBitmap frameBitmap = frame.SoftwareBitmap;
        WriteableBitmap bitmap = new WriteableBitmap(frameBitmap.PixelWidth, frameBitmap.PixelHeight);
        frameBitmap.CopyToBuffer(bitmap.PixelBuffer);
        var stream = new InMemoryRandomAccessStream();
        await bitmap.ToStream(stream, BitmapEncoder.JpegEncoderId);
        var detect = await faceClient.Face.DetectWithStreamAsync(stream.AsStream());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.