Handle of a Bitmap

S

Sumit Rajan

Greetings,

If I created a bitmap using:

Bitmap b = new Bitmap(50, 50);

And if I needed to get the handle associated with this bitmap (hWnd, I need
to do this because a function that I cannot touch requires it), how should I
go about doing this?

I would be extremely grateful if someone could help me out with this one.

Regards,
Sumit.
 
M

Marc Gravell

Not sure, but you could try GetHbitmap - however, I suspect that this will
be a clone - i.e. the second method won't be able to update the original.

Marc
 
S

Sumit Rajan

Marc Gravell said:
Not sure, but you could try GetHbitmap - however, I suspect that this will
be a clone - i.e. the second method won't be able to update the original.


Thanks, Marc. I have tried that out already. No luck. I guess I will have to
consult the authors of that function. :)

I appreciate your help.

Thanks.
Sumit.
 
I

Ignacio Machin ( .NET/ C# MVP )

Greetings,

If I created a bitmap using:

Bitmap b = new Bitmap(50, 50);

And if I needed to get the handle associated with this bitmap (hWnd, I need
to do this because a function that I cannot touch requires it), how shouldI
go about doing this?

I would be extremely grateful if someone could help me out with this one.

Regards,
Sumit.

Hi,

I do not think that you can do that, IIRC from some old thread a
Bitmap is just a memory representation of the image, it's not a Bitmap
object like in the unmanaged world.

What you could do though is P/invoke the Win32 API to create a Bitmap
and then use the hWnd from that.
 
C

Claes Bergefall

Sumit Rajan said:
Thanks, Marc. I have tried that out already. No luck. I guess I will have
to consult the authors of that function. :)

Not sure if this helps but...

Once you get the handle back you should be able to use Image.FromHBitmap to
create a new managed bitmap from it (including the changes made by the
external function).

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top