I try to load large image from a .RAW file into a System.Windows.Controls.Image by this code:
Dim pf As PixelFormat = PixelFormats.Gray16
Dim rawStride As Integer = Convert.ToInt32((Convert.ToInt32(RAWImage.ImageSize.Width) * pf.BitsPerPixel + 7) \ 8)
bitmap = BitmapSource.Create(Convert.ToInt32(RAWImage.ImageSize.Width), Convert.ToInt32(RAWImage.ImageSize.Width), 96, 96, _
pf, Nothing, ImagePixelvalues, rawStride)
MainPictureBox.Source = bitmap
where ImagePixelvalues is uint16().
My problem is about memory leakage caused by bitmapsource
. if I load for example 100 times RAW image in the Image Control, Windows Task Manager Performance shows that the Physical memory of the system increasing an after a while. This means that previous bitmapsource
are not released and GC
cannot collect them. Please let me know your idea about this How can i release bitmapsource
?