• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2169
  • Last Modified:

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
0
zitt
Asked:
zitt
1 Solution
 
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
 
bugrogerCommented:
You can also try
 Image1.Picture.Bitmap.Handle := "HBitmap/HDC"
or
 Image1.Picture.Bitmap.Handle := CreateCompatibleBitmap("HDC", "Width", "Height");
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
MadshiCommented:
Maybe simply "Image1.Picture.Bitmap.Handle := HBitmap;" ?

Regards, Madshi.
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now