In my WPF application, I need to load multiple images to display it in the UI. For that, I am using WriteableBitmap and then pass byte[] into Writeable.Writepixels(). While doing this, I am getting Out of memory exception after 5-6 execution. Image size would be 13-15 MB. I looked the memory consumption in Task manager, in which I noticed that whenever Writepixels() is called memory is drastically increased. kindly refer the below code:
WriteableBitmap bitmap = new WriteableBitmap(img.Width, img.Height, 96, 96, format, null);
var stride = data.Width * ((format.BitsPerPixel + 7) / 8);
bitmap.WritePixels(new Int32Rect(0, 0, data.Width, data.Height), data.Bytes, stride, 0);
return bitmap;
I searched all over the web for 2 days but, I can't find a suitable solution to dispose WriteableBitmap(). Please help me to resolve the solution.