Re: Display a bitmap from Win32, unmanaged code?



| First, related to deleting the underlying bitmap. In the low-level Win32
| code, the bitmap is reused and managed, there. This is code that's been
| around for many years and is stable which is why I don't want to fiddle
with
| it (but I probably will have to in the coming months).

Glad to know that. If the hBitmap will be reused, then we don't need to
delete it after creating the Bitmap object.

| Third, the proposed solution to move the dispose seems a bit fragile.
What
| is needed is a callback or method like is sued for the asynchronous load
for
| a pictureBox. In that way, the control could notify the caller when it's
done
| with the object. What's a bit odd is that it seems as though the
| pictureBox.image call is actually doing things asynchronously, else this
| would not be a problem. Is there a way to know, for sure, that the image
is
| done being displayed so that the data it was copying from can be
discarded?
| It's obvious that the call completing is not an indication that it's save
to
| dispose it.

The only time to Dispose the image is the when it is no longer needed. By
that, I mean at the time there is no reference that will use the image
again.
If the image is still be displayed in the PictureBox, then the PictureBox
holds a reference to it, when the OnPaint event happens, the PictureBox
needs the image to redraw itself.

So I think the best safe time to Dispose the old image is right after the
new image is assigned to the PictureBox.

Image old = this.theImage.Image;
this.theImage.Image = theBitmap;
if (old != null) old.Dispose();

I should have added this in my previous post.

Image.Dispose() for your reference:
http://msdn.microsoft.com/en-us/library/8th8381z.aspx

Note the Remarks section.

Hope this helps.

Best regards,

Jie Wang (jiewan@xxxxxxxxxxxxxxxxxxxx, remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • Re: Is there a default Windows palette for 256 colours?
    ... palette using Visual Studio 2008. ... bitmap file as a bitmap in the Resource Editor. ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.vc.mfc)
  • RE: WHy is the z-order being ignored in...
    ... bitmap to front. ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: MovieMaker Security Suite 2005 Case #: SRX050223602463
    ... I was impressed by the performance Microsoft ... > Review of MovieMaker Security, ... Telephonte Support replied with a non-existant answer to the ... > regarding my service, Zee Awad, my manager, would be very happy to hear ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: Confession of IT nightmare employee
    ... Thank you for the support. ... My office manager is a colleague. ... are afraid of the IT group. ... work desktop to install a piece of software. ...
    (microsoft.public.scripting.vbscript)
  • Re: WCF webservice over SSL and without
    ... Microsoft MSDN Online Support Lead ... You can send feedback directly to my manager at: ... WCF webservice over SSL and without ... I'm also familiar with how to setup a secure site in IIS. ...
    (microsoft.public.dotnet.framework.webservices)

Loading