B
bsnguy
I'm trying to do something that seems simple, but I'm missing a key point, it
seems. I have a DLL that returns a bitmap handle (hBitmap) and I want to
display that bitmap in a picturebox control. I can do it with the following
code:
hBitmap = win32DrawImage();
theBitmap = Bitmap.FromHbitmap(hBitmap);
UpdateImageBitmapMethod(theBitmap);
this.theImage.Image = theBitmap;
This works fine to display my image. The problem is that I'm display a lot
of them, in real-time, from a data acquisition device so if I put this in a
loop I run out of memory after a while.
So I said "hey, dispose of the bitmap" and I added
theBitmap.Dispose();
This works, for a while. The problem is that depending on what I do in the
UI, it seems that the bitmap is being disposed before the picturebox has
actually displayed it and I get an exception. Is there a better way to handle
this?
Thanks
seems. I have a DLL that returns a bitmap handle (hBitmap) and I want to
display that bitmap in a picturebox control. I can do it with the following
code:
hBitmap = win32DrawImage();
theBitmap = Bitmap.FromHbitmap(hBitmap);
UpdateImageBitmapMethod(theBitmap);
this.theImage.Image = theBitmap;
This works fine to display my image. The problem is that I'm display a lot
of them, in real-time, from a data acquisition device so if I put this in a
loop I run out of memory after a while.
So I said "hey, dispose of the bitmap" and I added
theBitmap.Dispose();
This works, for a while. The problem is that depending on what I do in the
UI, it seems that the bitmap is being disposed before the picturebox has
actually displayed it and I get an exception. Is there a better way to handle
this?
Thanks