SaveToBmp 函数是这样的,用它输出另一个Cbitmap没有问题!
void SaveToBmp(CBitmap *pBmp, LPCTSTR name)
{
CString str;
CFile fTest;
if(fTest.Open(name,CFile::modeRead))
{
fTest.Close();
str.Format("%s已经存在是否替换?",name);
if (MessageBox(str,"警告",MB_YESNO)!=IDYES) return;
}
BITMAP bp;
pBmp->GetBitmap(&bp);
int nScanWidth =bp.bmWidthBytes;
int nColors = (bp.bmBitsPixel>= 24) ? 0:256;
BITMAPFILEHEADER pBFH ;
pBFH.bfType =0x4d42;
pBFH.bfSize =sizeof(BITMAPINFOHEADER)+nScanWidth*bp.bmHeight+sizeof(BITMAPFILEHEADER);
pBFH.bfReserved1 = 0;
pBFH.bfReserved2 = 0;
pBFH.bfOffBits =sizeof(BITMAPINFOHEADER)+sizeof(BITMAPFILEHEADER);
BITMAPINFOHEADER pBIH ;
pBIH.biSize = sizeof(BITMAPINFOHEADER);
pBIH.biWidth = bp.bmWidth;
pBIH.biHeight = bp.bmHeight;
pBIH.biPlanes = 1;
pBIH.biBitCount = 32;//bp.bmBitsPixel;
pBIH.biCompression = 0; // non Compression.
pBIH.biSizeImage = nScanWidth*bp.bmHeight;
pBIH.biXPelsPerMeter = 0;
pBIH.biYPelsPerMeter = 0;
pBIH.biClrUsed = 0;
pBIH.biClrImportant = 0;
char* MyBits=new char[nScanWidth*bp.bmHeight];
char* BitsR=new char[nScanWidth*bp.bmHeight];
GetBitmapBits((HBITMAP)pBmp->m_hObject,nScanWidth*bp.bmHeight, BitsR);
for(int i=0;i<bp.bmHeight;i++)
memcpy(MyBits+(bp.bmHeight-1-i)*nScanWidth,BitsR+i*nScanWidth,nScanWidth);
CFile fp;
fp.Open(name,CFile::modeCreate|CFile::modeReadWrite);
fp.Write(&pBFH,sizeof(BITMAPFILEHEADER));
fp.Write(&pBIH,sizeof(BITMAPINFOHEADER));
fp.Write(MyBits,nScanWidth*bp.bmHeight);
fp.Close();
}
是不是有了 m_DC.SelectObject(&m_Bmp); 这一句后
在m_DC 中绘制的一切图形都会自动保存到m_Bmp中呢?或者是还需要什么更新呢?