Sunday 15 September 2013

c# picturebox memory releasing problem -


I would like to refresh a GUI picture box in a newby I repeatedly worker thread in C #. The image has been obtained from a camera in which the driver has been voted with a gateimage method which retries to display the image. Even if I allot the bitmap by using the "use" director and I clearly call GC, the memory is never distributed.

worker thread goes something like this:

  while (true) {// array of IR requested image (UInt16 with signal values) image = axLVCam.GetImage (0 ); Lut = axlvcam.GetLUT (1); Draw pictures (image, booty); //GC.Collect (); }  
a

while something like

  is the public zero DrawPicture (object image, object is limiting) <[...] // We image - Put it to the right type of system. UIInt16 [,] im = Image as System.UInt16 [,]; Float [] lutTempConversion = lut float []; Int lngWidthIrImage = im.GetLength (0); Int lngHeightIrImage = im.GetLength (1); Update image control // SetControlPropertyThreadSafe (tempTxtBox, "text", using String.Format (- (Bitmap bmp = new Bitmap (lngWidthIrImage, lngHeightIrImage)) {[... bitmap many operations on pixel ...] // Bitmap Ready for "{0: 0. #}", Latemap conversion [im [160, 100]]); //tempTxtBox.Text = string.Format ("{0: 00000}", IM [160, 100]); //System.Drawing.Image.FromHbitmap (bmp.GetHbitmap ()); Pic.Image = System.Drawing.Image.FromHbitmap (bmp.GetHbitmap ()); }}  

Problems arise with

pic.Image = System.Drawing.Image.FromHbitmap (bmp.GetHbitmap ());

actually Commenting on the code of the line, that as garbage collection such works better, appears with the problem

System is. Drawing Image FHTHMMAP (BMP GateHbitmap ())

Any advice to solve this memory leak?

Thanks a lot!

Image tools IDisposable , so you < Code> Dispute should call each Image example, when it is no longer necessary to try to change this line in your code:

  pic.Image = System.Drawing.Image.FromHbitmap (bmp.GetHbitmap ());  

with this:

  if (pic.Image! = Null) {pic.Image.Dispose (); } Pic.Image = System.Drawing.Image.FromHbitmap (bmp.GetHbitmap ());  

This will resolve the previous image (if any) before handing it over to the new image.


No comments:

Post a Comment