关于win32绘图出现无法显示彩色问题的解决
2008-04-20 21:51
573 查看
CView::OnCreate()中的代码如下:
ScrnWidth=GetSystemMetrics(SM_CXSCREEN);
ScrnHeight=GetSystemMetrics(SM_CYSCREEN);
CDC *dcpView;
CRect rcView;
GetClientRect(rcView);
dcpView=GetDC();
m_dcBack.CreateCompatibleDC(dcpView); //creates a memory device context (DC) compatible with the specified device.
// m_bmpBackDC.CreateCompatibleBitmap(&m_dcBack,ScrnWidth,ScrnHeight); //错误的
m_bmpBackDC.CreateCompatibleBitmap(&dcpView,ScrnWidth,ScrnHeight); //正确的写法
m_bmppOldBackDC=m_dcBack.SelectObject(&m_bmpBackDC);
m_brshBackDC.CreateSolidBrush(RGB(0,255,255));
m_brshpOldBackDC=m_dcBack.SelectObject(&m_brshBackDC);
m_dcBack.PatBlt(0,0,ScrnWidth,ScrnHeight,PATCOPY);
ReleaseDC(dcpView);
CView::OnDraw()即处理WM_PAINT消息的函数里还需要有
pDC->BitBlt(rcView.left,rcView.top,rcView.Width(),rcView.Height(),&m_dcBack,0,0,SRCCOPY);
但是在createCompatibleBitmap函数的第一个参数的选择要注意,如果给的hdc是内存设备号(memory device context )则此次创建的bitmap就只支持黑白色。如果要支持彩色需要给它你的设备号即上面程序的dcpView这样才能保证输出的是彩色。
可以查阅msdn上的CreateCompatibleBitmap函数说明:
The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device.
Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.
Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the hDC that was used to create the memory device context, as shown in the following code:
If an application sets the nWidth or nHeight parameters to zero, CreateCompatibleBitmap returns the handle to a 1-by-1 pixel, monochrome bitmap
ScrnWidth=GetSystemMetrics(SM_CXSCREEN);
ScrnHeight=GetSystemMetrics(SM_CYSCREEN);
CDC *dcpView;
CRect rcView;
GetClientRect(rcView);
dcpView=GetDC();
m_dcBack.CreateCompatibleDC(dcpView); //creates a memory device context (DC) compatible with the specified device.
// m_bmpBackDC.CreateCompatibleBitmap(&m_dcBack,ScrnWidth,ScrnHeight); //错误的
m_bmpBackDC.CreateCompatibleBitmap(&dcpView,ScrnWidth,ScrnHeight); //正确的写法
m_bmppOldBackDC=m_dcBack.SelectObject(&m_bmpBackDC);
m_brshBackDC.CreateSolidBrush(RGB(0,255,255));
m_brshpOldBackDC=m_dcBack.SelectObject(&m_brshBackDC);
m_dcBack.PatBlt(0,0,ScrnWidth,ScrnHeight,PATCOPY);
ReleaseDC(dcpView);
CView::OnDraw()即处理WM_PAINT消息的函数里还需要有
pDC->BitBlt(rcView.left,rcView.top,rcView.Width(),rcView.Height(),&m_dcBack,0,0,SRCCOPY);
但是在createCompatibleBitmap函数的第一个参数的选择要注意,如果给的hdc是内存设备号(memory device context )则此次创建的bitmap就只支持黑白色。如果要支持彩色需要给它你的设备号即上面程序的dcpView这样才能保证输出的是彩色。
可以查阅msdn上的CreateCompatibleBitmap函数说明:
The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device.
Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.
Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the hDC that was used to create the memory device context, as shown in the following code:
HDC memDC = CreateCompatibleDC ( hDC ); HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight ); SelectObject ( memDC, memBM );
If an application sets the nWidth or nHeight parameters to zero, CreateCompatibleBitmap returns the handle to a 1-by-1 pixel, monochrome bitmap
相关文章推荐
- 关于mysql-connector-odbc-5.1.13-win32.msi安装成功后,ODBC数据源管理器无法显示该MySql驱动的问题解决
- 解决关于vs2010中"w"无法 显示的问题
- 关于IPad,Iphone“无法加入网络”的可能出现的问题解决办法
- 【解决问题】文件名中含有中文,出现浏览器显示无法下载的情况
- 解决:Vista 系统中浏览网页速度慢或出现该页无法显示的问题
- 手把手教你:解决django关于图片无法显示的问题
- 关于双击cpp文件无法直接打开,VS2008提示“向程序发送命令时出现问题”的解决
- 关于Android高德地图4.12无法显示地图只显示Logo问题,非只添加 jniLibs.srcDirs = ['libs']就解决的
- 关于图片资源在android2.1/2.2/2.3下无法显示的问题以及解决方法
- 关于FPGA驱动TFT屏渐变显示出现条纹的问题解决
- 关于在server2012添加IIS功能中出现WinRM无法启动的问题解决过程
- 解决django关于图片无法显示的问题
- 关于Hibernate在weblogic中使用查询的时候该页无法显示的问题解决
- 请问如何解决WORD转HTML是出现的“内存或磁盘空间不足,无法显示或打印图片”这个问题?
- 如何解决Bootstrap的模态框在Framework7中使用出现遮罩无法显示的问题?
- 解决JAVA关于JTable列名无法显示问题
- vs2008与IIS 7.0使用在vista上时出现的问题及解决方法(Internet Explorer 无法显示该页面)(VS2008: IE Cannot Display Web Page)
- 关于Window 7 系统磁盘无法显示的问题的解决办法
- 关于CSS中内层使用float导致外层的背景无法显示的问题的解决方法
- fckeditor部署到weblogic出现xml无法读取及样式不能显示问题的解决方法