Page 1 of 1

WriteableBitmap Displays Unexpected Red X

PostPosted: Sun Dec 30, 2018 11:55 pm
by njsokalski
I am new to AForge, so maybe I am doing something wrong, but here is my current code:
Code: Select all
Dim videoencodingprops As VideoEncodingProperties = CType(Me.mc.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview), VideoEncodingProperties)
Dim softwarebmp As SoftwareBitmap = (Await Me.mc.GetPreviewFrameAsync(New Windows.Media.VideoFrame(BitmapPixelFormat.Bgra8, CInt(videoencodingprops.Width), CInt(videoencodingprops.Height)))).SoftwareBitmap
Dim writeablebmp As New WriteableBitmap(softwarebmp.PixelWidth, softwarebmp.PixelHeight)
softwarebmp.CopyToBuffer(writeablebmp.PixelBuffer)
Dim bmp As Drawing.Bitmap = CType(writeablebmp, Drawing.Bitmap)
Dim blobcntr As New AForge.Imaging.BlobCounter()
blobcntr.ProcessImage(bmp)
Dim blobs As AForge.Imaging.Blob() = blobcntr.GetObjectsInformation()
writeablebmp = CType(bmp, WriteableBitmap)
Me.imgPreview.Source = writeablebmp

This code displays a preview from a MediaCapture (Me.mc) in a UWP Image control (Me.imgPreview). However, it is displaying a big red X (1 pixel thick, corner to corner) on top of the WriteableBitmap / Image. I can still see the preview from the camera, so the red X is obviously part of the image. If I remove the following line:
Code: Select all
writeablebmp = CType(bmp, WriteableBitmap)

Then the red X is not displayed. The only places where bmp (the Drawing.Bitmap being converted & assigned to the WriteableBitmap in the line mentioned) is used is when it is declared and when I call ProcessImage. Could either of these lines be causing this? If they are (which I would find surprising), why is it using the corners, and why red? Any help would be appreciated, thanks.

Re: WriteableBitmap Displays Unexpected Red X

PostPosted: Mon Dec 31, 2018 11:50 am
by andrew.kirillov
Big red cross is usually shown when exception happens. Check if any exceptions are thrown in your code. Maybe those get swallowed by some try/catch block.