Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to display 8k RGB image from a RAW byte array which I get from a framegrabber in wpf control at High fps speed. I am able to successfully convert and the byte array to BitmapSource and display it in the image windows in WPF. But since the grabber is generating images at around 5 FPS after display i am releasing the hold to the object but GC takes time collect the memory within which my application memory increases and freezes the application and my system. How to properly dispose the BitmapSource(CachedBitmap) created using the below method. Please help me out in disposing the object after use.

Here is my byte array to bitmap conversion code,

C#
int Width = 7680;
int Height = 4320;
PixelFormat PixelFormat = PixelFormats.Bgr24;
int BytesPerPixel = 3;

public BitmapSource ByteToImage(byte[] imageData)
{
    var stride = BytesPerPixel * Width;
    BitmapSource bitmapSource = BitmapSource.Create(Width, Height, 96d, 96d, PixelFormat, null, imageData, stride);
    bitmapSource.Freeze();
    return bitmapSource;
}


What I have tried:

I tried GC.Collect() while image change but it doesn't work.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900