如何将bmp位图转换为文本文件?给个程序参考 100分 如何将bmp位图转换为文本文件?给个程序参考 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你看看这个保存屏幕的函数SaveBmp,里面就有将bmp位图转换为文本文件。void CCaptureDlg::SaveBmp(){ 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);} bmp不可能转换为文本,难道你只想将.bmp换成.txt http://www.programmersheaven.com/zone16/cat99/3228.htm 找windows下能够兼容C99的编译器 紧急问题 webbrowser控件如何捕获用户鼠标点击事件? 请问VC怎样异常处理 为什么我设了鼠标钩子后只能钩住我的程序窗口中的鼠标消息 COM 使用CSplitterWnd类拆分窗口时,想要固定分隔条,该怎么办? compile没问题,build出错(解决了立刻结帖) 我就这么点分,请教98和nt下钩子有什么不同 怎样用mfc打开文件夹里的视频文件 奇怪,我在打印预览中看到在屏幕的左上角,但是打印出来后移到纸张的右下角.这是为何? IHTMLDOMNode 问题
void CCaptureDlg::SaveBmp()
{
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);
}