CreateBitmap创建的位图,画出来的彩色图效果很差是什么原因?

ameyume
博客专家认证
2010-11-23 11:45:58
1.声明保存位图的指针
unsigned char *g_pSheet_bits = NULL;

2.取得位图信息保存在char指针所指的区域
if (!g_pSheet_bits) {
g_pSheet_bits = new unsigned char[client_w * client_h * 4];
}
memset(g_pSheet_bits, 0, sizeof(char) * client_w * client_h * 4);
::GetBitmapBits(wbuf_bitmap, client_w * client_h * 4, g_pSheet_bits);

3.根据取得位图信息创建CBitmap对象,使用CreateBitmap方法创建,
CBitmap m_bitmap;

m_bitmap.CreateBitmap(rc.Width(), rc.Height(), 1, 32, g_pSheet_bits); // 第3,4个参数可以这样设置吗?第4个参数设置为24,64, 256等报参数错误。
TRACE("--------- %d \n", GetLastError());

4.在onPaint函数中通过BitBlt画bitmap
CPaintDC dc(this);
CDC memDc;
memDc.CreateCompatibleDC(&dc);
CBitmap *pOldBit;

pOldBit = memDc.SelectObject(&m_bitmap);
dc.BitBlt(m_bmpRect.left,
m_bmpRect.top,
m_bmpRect.Width(),
m_bmpRect.Height(),
&memDc,
0,
0,
SRCCOPY);

memDc.SelectObject(pOldBit);

以上就是所有的画图操作,在dialog对话框中的onPaint函数中画的。
画出的图虽然是彩色的但只有一个轮廓,效果非常差。
请问是什么愿意?
...全文
285 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ameyume 2010-11-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyparrot 的回复:]
你这个位图到底是多少色的啊?是不是32,或者16,8,是看你的图像数据具体多少位表示一个像素啊。不是乱填。
[/Quote]
多谢,那怎么知道wbuf_bitmap是多少色的?
wbuf_bitmap是CBitmap类型的,有属性可以取得是多少色吗?
快乐鹦鹉 2010-11-23
  • 打赏
  • 举报
回复
你这个位图到底是多少色的啊?是不是32,或者16,8,是看你的图像数据具体多少位表示一个像素啊。不是乱填。
ameyume 2010-11-23
  • 打赏
  • 举报
回复
多谢!
用GetDeviceCaps取得PLANES和BITSPIXEL了。
结果也是1和32.
libinfei8848 2010-11-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 m_tornado 的回复:]
HBITMAP CreateBitmap(
int nWidth, // bitmap width, in pixels
int nHeight, // bitmap height, in pixels
UINT cPlanes, // number of color planes
UINT cBitsPerPel, // number of bits to identif……
[/Quote]

++++
m_tornado 2010-11-23
  • 打赏
  • 举报
回复
HBITMAP CreateBitmap(
int nWidth, // bitmap width, in pixels
int nHeight, // bitmap height, in pixels
UINT cPlanes, // number of color planes
UINT cBitsPerPel, // number of bits to identify color
CONST VOID *lpvBits // color data array
);

cBitsPerPel
[in] Specifies the number of bits required to identify the color of a single pixel.
lpvBits
[in] Pointer to an array of color data used to set the colors in a rectangle of pixels. Each scan line in the rectangle must be word aligned (scan lines that are not word aligned must be padded with zeros). If this parameter is NULL, the contents of the new bitmap is undefined.

看msdn是设置的32位图片啊

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧