关于win32绘图出现无法显示彩色问题的解决
来源:互联网 发布:php娱乐网源码 编辑:程序博客网 时间:2024/04/29 12:48
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:
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
- 关于win32绘图出现无法显示彩色问题的解决
- pycharm中绘图无法显示的解决
- 关于chm无法显示的问题(已解决)
- 关于系统托盘图标(systemtray)无法显示问题的解决
- 关于系统托盘图标(systemtray)无法显示问题的解决
- 关于系统托盘图标(systemtray)无法显示问题的解决
- 关于解决打开CHM文件无法显示的问题
- 关于drawing_area绘图区的显示问题
- 关于drawing_area绘图区的显示问题
- 关于drawing_area绘图区的显示问题
- COMSOL绘图时出现显示错误的解决
- Python 中,matplotlib绘图无法显示中文的问题
- Python 中,matplotlib绘图无法显示中文的问题
- Python中,matplotlib绘图无法显示中文的问题
- 关于最近出现的病毒导致桌面无法显示的问题
- 关于spring在service层catch异常而出现无法回滚的问题的解决
- 关于启动wampserver出现的php.exe 无法启动此程序问题的解决
- 关于jar生成exe时出现背景图片无法显示的问题
- wince下ce3.0数据库连接
- How to get file from classpath
- oracle–概念和术语
- 发布一个自己做的资料收藏夹软件(可语法着色)
- 虚拟机(xen)中credit调度算法分析(3)
- 关于win32绘图出现无法显示彩色问题的解决
- [转]常用的正则表达式
- 数独设计-领域模型分析初步
- 深度解析VC中的消息传递机制
- 共和国最年轻上将:叶飞39岁授衔
- 独上巅峰
- JSP开发工具的选择(1)
- 从今天开始Linux
- 理解矩阵(读csdn孟岩之理解矩阵)