Save CBitmap object to disk
-
I save a CBitmap object to disk with this code : CDC * pDC = GetDC(); CBitmap Bitmap; Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY); Image.Attach(Bitmap); Image.Save(_T("xxx.bmp")); but the bitmap I saved was completely black Some one plz help me :rose:
-
I save a CBitmap object to disk with this code : CDC * pDC = GetDC(); CBitmap Bitmap; Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY); Image.Attach(Bitmap); Image.Save(_T("xxx.bmp")); but the bitmap I saved was completely black Some one plz help me :rose:
capint wrote:
Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY); Image.Attach(Bitmap);
this creates only the bitmap object, allocates resources for the bitmap and the color format is compatible with the Device context, but the image it initially contains is blank, you need to fill the image in to the allocated bitmap resource. I assume you want the image in the Device context then you need to copy the bitmap from dc to this bitmap,
CBitmap Bitmap;
Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&Bitmap);// Copy the bits from the on-screen DC into the
// in-memory DC
dcMemory.BitBlt(0, 0, screenMaxX, screenMaxY, pDC,
0, 0, SRCCOPY);dcMemory.SelectObject(pOldBitmap);
-
capint wrote:
Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY); Image.Attach(Bitmap);
this creates only the bitmap object, allocates resources for the bitmap and the color format is compatible with the Device context, but the image it initially contains is blank, you need to fill the image in to the allocated bitmap resource. I assume you want the image in the Device context then you need to copy the bitmap from dc to this bitmap,
CBitmap Bitmap;
Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&Bitmap);// Copy the bits from the on-screen DC into the
// in-memory DC
dcMemory.BitBlt(0, 0, screenMaxX, screenMaxY, pDC,
0, 0, SRCCOPY);dcMemory.SelectObject(pOldBitmap);
-
I save a CBitmap object to disk with this code : CDC * pDC = GetDC(); CBitmap Bitmap; Bitmap.CreateCompatibleBitmap(pDC,screenMaxX, screenMaxY); Image.Attach(Bitmap); Image.Save(_T("xxx.bmp")); but the bitmap I saved was completely black Some one plz help me :rose: