~~我在对话框里有个picture用LoadImage()读入一个BMP,然后显示,问题在这里,因为BMP的尺寸比picture小,而我保存时是将整个pictureDC保存下来了,请问怎么才能按图片原来的大小保存这是我保存BMP的代码(是将整个picture DC保存的)望高手给出代码,谢谢。         CDC  memDC;
CRect rect;
m_Dest.GetClientRect(rect);//m_Dest就是picture memDC.CreateCompatibleDC(m_Dest.GetDC());
CBitmap bm;
int Width = rect.Width();
int Height = rect.Height();
bm.CreateCompatibleBitmap(m_Dest.GetDC(), Width, Height);
CBitmap*  pOld = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, Width, Height, m_Dest.GetDC(), 0, 0, SRCCOPY);
memDC.SelectObject(pOld);
BITMAP  btm;
bm.GetBitmap(&btm);
DWORD  size = btm.bmWidthBytes * btm.bmHeight;
LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);
BITMAPFILEHEADER   bfh;
/////////////////////////////////////////////
BITMAPINFOHEADER  bih;
bih.biBitCount = btm.bmBitsPixel;
bih.biClrImportant = 0;
bih.biClrUsed = 0;
bih.biCompression = 0;
bih.biHeight = btm.bmHeight;
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = size;
bih.biWidth = btm.bmWidth;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
GetDIBits(m_Dest.GetDC()->GetSafeHdc(),bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
bfh.bfReserved1 = bfh.bfReserved2 = 0;
bfh.bfType = ((WORD)('M'<< 8)|'B');
bfh.bfSize = 54 + size;
bfh.bfOffBits = 54;
CFile  bf;
if(bf.Open(lpFilePath, CFile::modeCreate | CFile::modeWrite))
{
bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData, size);
bf.Close();

}
GlobalFreePtr(lpData);

解决方案 »

  1.   

    ~~~这是我读入位图的一些代码
    CBitmap b;
    BITMAP bm;
    hbmp = (HBITMAP)LoadImage(NULL, _T(lpFilePath), IMAGE_BITMAP,
    0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
    b.Attach(hbmp); b.GetBitmap(&bm);
      

  2.   

    bm里面有宽度高度的值
    CDC  memDC;
    CRect rect;
    m_Dest.GetClientRect(rect);//m_Dest就是picture这几句话里面的rect使用bm里面的宽度高度代替就行了
      

  3.   

    1:创建内存兼容DC
    2:为内存兼容DC选择合适大小的位图
    3:使用Bitblt把屏幕上合适位置的一块区域拷贝到内存DC中
    4:把位图替换下来
    5:保存位图