hbitmap to TImage?

I have an ActiveX component which returns a windows handle to a Bitmap.
I need to get this handle into a TImage which can be saved to a file and/or displayed as part of an image component on the background of my form.

I have been able to get a HDC to the bitmap and draw on the bitmap... but I cannot figure out how to "copy" the data into a TImage.

MyHDC := CreateCompatibleDC(0);
    // ' Selects entire bitmap to this DC
SelectObject(MyHDC, HGDIOBJ(SkinObject.hEntireBitmap));

I'm sure I'm just missing something simple.
John
zittAsked:
Who is Participating?
 
MadshiConnect With a Mentor Commented:
Maybe simply "Image1.Picture.Bitmap.Handle := HBitmap;" ?

Regards, Madshi.
0
 
bugrogerCommented:
Hi zitt,


{...}
MemBitmap        := TBitmap.Create;
MemBitmap.Handle := "HBITMAP";

Image1.Width  := MemBitmap.Width;
Image1.Height := MemBitmap.Height;
Image1.Canvas.Draw(0, 0, MemBitmap);

MemBitmap.Free;
{...}

GL
 Bug

0
 
bugrogerCommented:
If
 MemBitmap.Handle := "HBITMAP/HDC";
does not work try this:

 MemBitmap.Handle := CreateCompatibleBitmap("HDC", "Width", "Height");

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
bugrogerCommented:
You can also try
 Image1.Picture.Bitmap.Handle := "HBitmap/HDC"
or
 Image1.Picture.Bitmap.Handle := CreateCompatibleBitmap("HDC", "Width", "Height");
0
 
GwenaCommented:
listening :-)
0
 
zittAuthor Commented:
Short, simple and it seems to work.
I could have swore I tried this; however, it was likely do to inconsitancies I have with the OCX control I'm using.

John
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.