:: AForge.NET Framework :: Articles :: Forums ::

WriteableBitmap Displays Unexpected Red X

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

WriteableBitmap Displays Unexpected Red X

Postby njsokalski » Sun Dec 30, 2018 11:55 pm

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(, VideoEncodingProperties)
Dim softwarebmp As SoftwareBitmap = (Await Windows.Media.VideoFrame(BitmapPixelFormat.Bgra8, CInt(videoencodingprops.Width), CInt(videoencodingprops.Height)))).SoftwareBitmap
Dim writeablebmp As New WriteableBitmap(softwarebmp.PixelWidth, softwarebmp.PixelHeight)
Dim bmp As Drawing.Bitmap = CType(writeablebmp, Drawing.Bitmap)
Dim blobcntr As New AForge.Imaging.BlobCounter()
Dim blobs As AForge.Imaging.Blob() = blobcntr.GetObjectsInformation()
writeablebmp = CType(bmp, WriteableBitmap)
Me.imgPreview.Source = writeablebmp

This code displays a preview from a MediaCapture ( 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.
Posts: 10
Joined: Thu Dec 20, 2018 11:46 pm

Re: WriteableBitmap Displays Unexpected Red X

Postby andrew.kirillov » Mon Dec 31, 2018 11:50 am

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.
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Return to AForge.NET Framework