Solved

hbitmap to TImage?

Posted on 2001-07-31
6
2,024 Views
Last Modified: 2008-02-01
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
Comment
Question by:zitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:bugroger
ID: 6336920
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
 
LVL 2

Expert Comment

by:bugroger
ID: 6336948
If
 MemBitmap.Handle := "HBITMAP/HDC";
does not work try this:

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

0
 
LVL 2

Expert Comment

by:bugroger
ID: 6336951
You can also try
 Image1.Picture.Bitmap.Handle := "HBitmap/HDC"
or
 Image1.Picture.Bitmap.Handle := CreateCompatibleBitmap("HDC", "Width", "Height");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 6336983
Maybe simply "Image1.Picture.Bitmap.Handle := HBitmap;" ?

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6338821
listening :-)
0
 

Author Comment

by:zitt
ID: 6362689
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question