从内存DC创建bmp文件
来源:互联网 发布:ipad怎么备份所有数据 编辑:程序博客网 时间:2024/06/05 06:23
http://zhidao.baidu.com/question/27257644.html
HDC hScrDC, hMemDC;
int width, height;
//the pointer will save all pixel point's color value
BYTE *lpBitmapBits = NULL;
//creates a device context for the screen device
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
//get the screen point size
width = GetDeviceCaps(hScrDC, HORZRES);
height = GetDeviceCaps(hScrDC, VERTRES);
//creates a memory device context (DC) compatible with the screen device(hScrDC)
hMemDC = CreateCompatibleDC(hScrDC);
//initialise the struct BITMAPINFO for the bimap infomation,
//in order to use the function CreateDIBSection
// on wince os, each pixel stored by 24 bits(biBitCount=24)
//and no compressing(biCompression=0)
BITMAPINFO RGB24BitsBITMAPINFO;
ZeroMemory(&RGB24BitsBITMAPINFO, sizeof(BITMAPINFO));
RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RGB24BitsBITMAPINFO.bmiHeader.biWidth = width;
RGB24BitsBITMAPINFO.bmiHeader.biHeight = height;
RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;
//use the function CreateDIBSection and SelectObject
//in order to get the bimap pointer : lpBitmapBits
HBITMAP directBmp = CreateDIBSection(hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO,
DIB_RGB_COLORS, (void **)&lpBitmapBits, NULL, 0);
HGDIOBJ previousObject = SelectObject(hMemDC, directBmp);
// copy the screen dc to the memory dc
BitBlt(hMemDC, 0, 0, width, height, hScrDC, 0, 0, SRCCOPY);
//if you only want to get the every pixel color value,
//you can begin here and the following part of this function will be unuseful;
//the following part is in order to write file;
//bimap file header in order to write bmp file
BITMAPFILEHEADER bmBITMAPFILEHEADER;
ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));
bmBITMAPFILEHEADER.bfType = 0x4d42; //bmp
bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + ((width*height)*3); ///3=(24 / 8)
//write into file
FILE *mStream = NULL;
if((mStream = fopen(filename, "wb")))
{
//write bitmap file header //文件头
fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);
//write bitmap info //数据头
fwrite(&(RGB24BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);
//write bitmap pixels data //数据信息
fwrite(lpBitmapBits, 3*width*height, 1, mStream);
//close file
fclose(mStream);
#ifdef _UNICODE
WCHAR wBuffer[1024] ;
mbstowcs(wBuffer, filename, strlen(filename)+1);
CStringW str;
str.Format(_T("文件保存在: "));
str.AppendFormat(wBuffer);
MessageBoxW(str);
TRACE(str);
#else
CStringA str;
str.format("文件保存在: ");
str.AppendFormat(filename);
MessageBoxA(str);
#endif//_UNICODE
}
//delete
DeleteObject(hMemDC);
DeleteObject(hScrDC);
DeleteObject(directBmp);
DeleteObject(previousObject);
- 从内存DC创建bmp文件
- 从内存DC中保存成叠加的bmp文件
- [SDK]创建DC,保存DC为BMP文件
- 保存DC到BMP文件
- 保存DC到BMP文件 win32
- Bitmap的加载(从屏幕DC到内存DC)
- 创建bmp文件类
- VC创建BMP文件
- 自定义DC的RECT保存为bmp文件
- 图片操作(二)--保存DC到BMP文件 win32
- 内存DC
- 内存DC
- 内存DC
- 内存DC
- DC保存至BMP图像
- 将DC保存到bmp
- DC保存至BMP图像
- 关于创建内存DC用于贴图的注意事项
- HTML属性实例
- [转]C++高进度测试程序运行的时间
- C# 用户自定义UserControl控件使用
- android 源码下载过程和工具速览
- 【成功之路】 让人喜欢的30个原则
- 从内存DC创建bmp文件
- 活动窗口(Active),焦点窗口(Focus),IsDialogMessage,
- DM-V-VM
- linux常用命令
- C#中使用Property Grid 控件 学习笔记(一)
- To Excel(XML)
- 区分strcmp 与strncmp 、strcpy与strncpy
- 刚开通博客,希望记录自己的一些经历
- UVa Problem 10160 Servicing Stations (服务站)