MFC(如何将视图窗口中的自绘图,以图片方式保存最好是.BMP格式!) 在线等,立马给分! 如何将视图窗口中的自给图,以图片方式保存最好是.BMP格式!)比如,我在图口中画了一个三角形,两个圆如何把他们保存成图形文件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下的代码是抓屏保存位图的,你可以参考一下,把你画布的内容拷贝到兼容内存场景中去就可以了 CDC dc; dc.CreateDC("DISPLAY",NULL,NULL,NULL); CBitmap bm; int Width=GetSystemMetrics(SM_CXSCREEN); int Height=GetSystemMetrics(SM_CYSCREEN); bm.CreateCompatibleBitmap(&dc,Width,Height); CDC tdc; tdc.CreateCompatibleDC(&dc); CBitmap*pOld=tdc.SelectObject(&bm); tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY); tdc.SelectObject(pOld); BITMAP btm; bm.GetBitmap(&btm); DWORD size=btm.bmWidthBytes*btm.bmHeight; LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);///////////////////////////////////////////// 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(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);// bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱////////////////////////////// static int filecount=0; CString name; name.Format("pict%04d.bmp",filecount++); name=m_Path+name; BITMAPFILEHEADER bfh; bfh.bfReserved1=bfh.bfReserved2=0; bfh.bfType=((WORD)('M'<< 8)|'B'); bfh.bfSize=54+size; bfh.bfOffBits=54; CFile bf; if(bf.Open(name,CFile::modeCreate|CFile::modeWrite)){ bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER)); bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER)); bf.WriteHuge(lpData,size); bf.Close(); nCount++; } GlobalFreePtr(lpData); if(nCount==1) m_Number.Format("%d picture captured.",nCount); else m_Number.Format("%d pictures captured.",nCount); UpdateData(FALSE); VC程序界面编写,难。。。 关于CAxwindow 窗口的疑惑 高手进~~~~~~~~~~~ vc中有没有得到“相对路径”的函数 很困惑,使用const 替换#define 出现的问题 怎样不规则图形内的位图象素数目 怎样制作插件的安装程序 $$$十万火急啊!!哪位好兄弟帮帮小弟啊!多谢了!$$$ 进程间通信的问题 变量命名规则 CListCtrl中关于()的问题 如何修改checkbox控件(请那为高手在这里个小妹讲详细) 如何把m_pRecord指向的那条记录全部复制到结构相同的另外一张表里面呢?
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL);
CBitmap bm;
int Width=GetSystemMetrics(SM_CXSCREEN);
int Height=GetSystemMetrics(SM_CYSCREEN);
bm.CreateCompatibleBitmap(&dc,Width,Height);
CDC tdc;
tdc.CreateCompatibleDC(&dc);
CBitmap*pOld=tdc.SelectObject(&bm);
tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
tdc.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
DWORD size=btm.bmWidthBytes*btm.bmHeight;
LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
/////////////////////////////////////////////
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(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
// bm.GetBitmapBits(size,lpData); //此函数在处理5-5-5模式的16位色下会出现颜色混乱
//////////////////////////////
static int filecount=0;
CString name;
name.Format("pict%04d.bmp",filecount++);
name=m_Path+name;
BITMAPFILEHEADER bfh;
bfh.bfReserved1=bfh.bfReserved2=0;
bfh.bfType=((WORD)('M'<< 8)|'B');
bfh.bfSize=54+size;
bfh.bfOffBits=54;
CFile bf;
if(bf.Open(name,CFile::modeCreate|CFile::modeWrite)){
bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
bf.WriteHuge(lpData,size);
bf.Close();
nCount++;
}
GlobalFreePtr(lpData);
if(nCount==1)
m_Number.Format("%d picture captured.",nCount);
else
m_Number.Format("%d pictures captured.",nCount);
UpdateData(FALSE);