用VC的File::Open打开的文件怎么显示出来呀?现在要输出一幅位图,读出来的东西怎么转到DC中去?还有怎么保存成位图
解决方案 »
- 请教两个关于打印预览的问题!
- 用Embeded Visual C++(EVC)写一个在WindowsCE.net系统下客机下载主服务器(windowsXP)一个图片并显示在对话框中的小程序
- 关于按钮的问题!
- 求vc6读写xml文件的例子
- 有谁用过FlexCell表格控件吗?哪里有VC的实例代码可下载?
- 求VC电梯模拟程序的源代码!急用!
- 请问怎样把Gif转化为Bitmap,或哪里提供源代码下载?
- 我在应用程序中想直接执行windownt控制面板中的拨号程序,但我不知道这程序名,怎样得到这文件名???
- 如何显示文本
- 请高手帮忙解决CRecordset问题。急,谢谢。
- Outlook 不让我看附件, 怎么办?
- 怎么使其它程序无法得我的程序的窗口名?请教!
BOOL SaveBMP(HBITMAP hBitmap,const char *pFileName)
{
if (hBitmap == NULL)
return FALSE;
//验证pFileName
if (pFileName == NULL)
return FALSE; //创建DIB
BITMAP bm;
if (::GetObject(hBitmap,sizeof(BITMAP),&bm) <= 0)
return FALSE;
long nBmpWidth = bm.bmWidth;
long nBmpHeight = bm.bmHeight;
long nBmpWidthBytes = (nBmpWidth*3+3)/4*4;
long nImageSize24 = nBmpWidthBytes*nBmpHeight;
BYTE *pSrc = (BYTE *)::GlobalAlloc(GPTR,nImageSize24);//source dib
if (pSrc == NULL)
return FALSE;
/////////////////////////////////////////////
BITMAPINFOHEADER bifh;
bifh.biSize=sizeof(BITMAPINFOHEADER);
bifh.biWidth=nBmpWidth;
bifh.biHeight=nBmpHeight;
bifh.biPlanes=1;
bifh.biBitCount=24;//24 bit
bifh.biCompression=0;
bifh.biSizeImage=nImageSize24;
bifh.biXPelsPerMeter=0;
bifh.biYPelsPerMeter=0;
bifh.biClrUsed=0;
bifh.biClrImportant=0;
HDC hDC = ::GetDC(NULL);
long nRet;
nRet = ::GetDIBits(hDC,hBitmap,0,nBmpHeight,pSrc,(BITMAPINFO*)&bifh,DIB_RGB_COLORS);
if (nRet != nBmpHeight)
{
DeleteDC(hDC);
GlobalFree(pSrc);
return FALSE;
}
::ReleaseDC(NULL,hDC);
//////////////////////////////////////////
BITMAPFILEHEADER bfh;
bfh.bfReserved1=bfh.bfReserved2=0;
bfh.bfType=((WORD)('M'<< 8)|'B');
bfh.bfSize=54+nImageSize24;
bfh.bfOffBits=54;
FILE *stream;
if( (stream = fopen( pFileName, "w" )) != NULL )
{
fwrite(&bfh,1,sizeof(BITMAPFILEHEADER),stream);
fwrite(&bifh,1,sizeof(BITMAPINFOHEADER),stream);
fwrite(pSrc,1,nImageSize24,stream);
fclose( stream );
}
else
return FALSE;
GlobalFree(pSrc);
return TRUE;
}