Click to See Complete Forum and Search --> : How to copy image from Bitmap to CBitmap?


TimAlex
April 26th, 2006, 11:40 PM
I have to objects: Bitmap (GDI+) and CBitmap (GDI). Can I copy image from first to second and how to do it? Thanks, SME.

cindyonlyone
April 27th, 2006, 02:22 AM
The bitmap data doesn't have difference between GDI+ and GDI, so you can use the same way to copy from the first to the second, only the CF_BITMAP clipboard format needed.

Cindy
--------------------------------------------------------------------------
For high quality flow/diagram MFC/C++ Visio 12 Like visualization Source Code,download XD++ at:
http://www.********.net

TimAlex
April 27th, 2006, 05:05 AM
Thanks, Cindyonlyone. Can you post tiny code sample?

ovidiucucu
April 27th, 2006, 10:32 AM
I have to objects: Bitmap (GDI+) and CBitmap (GDI). Can I copy image from first to second and how to do it?
Yes.
Simply create a CBitmap object and attach to it the handle retrieved by Bitmap::GetHBITMAP.
Here is the exmple:
Bitmap* pBitmap = Bitmap::FromFile(L"c:\\courage.bmp");

HBITMAP hBitmap = NULL;
pBitmap->GetHBITMAP(Color(0,0,0), &hBitmap);

CBitmap bitmap;
BOOL bSuccess = bitmap.Attach(hBitmap);
delete pBitmap;