Board index » cppbuilder » Help with BitBlt

Help with BitBlt

Hello !

I'm trying to use BitBlt from windows API to save a displayed bitmap
into memory then restore it.

1 This function needs HDC as parameters for the handles of the source
and destination bitmaps.
Can I use HBITMAP for HDC ? I've tried this but it doesn't work:

Graphics::TBitmap Saved_Bitmap;
TImage Image1;

// Save
        BitBlt( Saved_Bitmap -> Handle, 0, 0, Saved_Bitmap -> Width,
Saved_Bitmap -> Height,
                                                Image1->Picture->Bitmap->Handle, 0, 0, SRCCPY);

// Restore
        BitBlt( Image1->Picture->Bitmap->Handle, 0, 0, Image1 -> Width, Image1
-> Height, Saved_Bitmap ->
                                                Handle, 0, 0, SRCCPY);

In fact it seems it doesn't do anything.

2 Is there a quicker way to do it ?

Thanks for your help.
Please also answer by mail.

--
----------------------------------------
Damien Saussac
Ingnieur en Informatique
Institut National de l'Audiovisuel

ICQ# 148 00 862
d...@ina.fr ou Damien.Saus...@wanadoo.fr

 

Re:Help with BitBlt


Forget it !
I found out that I have to use the Canvas -> Handle and not the Bitmap
-> Handle

--
----------------------------------------
Damien Saussac
Ingnieur en Informatique
Institut National de l'Audiovisuel

ICQ# 148 00 862
d...@ina.fr ou Damien.Saus...@wanadoo.fr

Re:Help with BitBlt


From your snippet I gather you're trying to save the contents of a TImage. Try this:

Graphics::TBitmap *Surface = new Graphics::TBitmap;
int w = Image1->Width;
int h = Image1->Height;

 Surface->Height = h;
Surface->Width = w;

To save the current contents of Image1,

BitBlt(Surface->Canvas->Handle,0,0,w,h,Image1->Canvas->Handle,0,0,SRCCOPY);

To restore,

BitBlt(Image1->Canvas->Handle,0,0,w,h,Surface->Canvas->Handle,0,0,SRCCOPY);

Don't forget to

delete Surface;

at the appropriate time (whenever you're finished w/ it).

Bon chance, mon ami.

Other Threads