Board index » cppbuilder » HBITMAP and TBitmap

HBITMAP and TBitmap

I am trying to place a DIB into a TBitmap and am having smoe trouble.
I have an HBITMAP handle to the DIB; what's the best way to "convert"
this to a TBitmap?

Thanks,
Michael

 

Re:HBITMAP and TBitmap


I don't think that you need to convert it to TBitmap, I think that you only
need to assing it.
What I understand a about TBitmap is that it is actually a Windows Bitmap
Object and a Windows Palette Object encapsulated together. I guess the only
thing that you have to do is to assign your HBITMAP handle to
TBitmap->Handle  property.

Bitmap1->Handle=YourHBITMAPhandle

Hope this help.

--
Jorge E. Perez
jorg...@unm.edu

Re:HBITMAP and TBitmap


I just tried the following code and it worked fine

    HBITMAP hbitmap;
    Graphics::TBitmap *bitmap;
    bitmap=new Graphics::TBitmap();
    // load a bitmap from disk and make it DIB
    hbitmap=LoadImage(NULL,"c:\\winnt\\winnt256.bmp",IMAGE_BITMAP,   \
                    0,0,LR_DEFAULTSIZE|LR_CREATEDIBSECTION|LR_LOADFROMFILE);
    bitmap->HandleType=bmDIB;
    bitmap->Handle=hbitmap;  // Assign it to the TBitmap object
    Canvas->Draw(1,1,bitmap);  // Draw it over the main form
    delete bitmap;

--
Jorge E. Perez
jorg...@unm.edu

Re:HBITMAP and TBitmap


Hi Michael,

Quote
> I am trying to place a DIB into a TBitmap and am having smoe trouble.
> I have an HBITMAP handle to the DIB; what's the best way to "convert"
> this to a TBitmap?

Where are you obtaining the DIB from?  The SetDIBits() function is used to
convert from a DIB to a DDB...

SetDIBits(ScreenDC, HBitmap, 0, lpBitmapInfo->bmiHeader.biHeight,
          bits, lpBitmapInfo, DIB_RGB_COLORS);

Perhaps you have a DIBSection?

Good luck.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

Other Threads