16位色深屏幕下,可以绘出32位色深的图形吗?

sunlin7 sunlin7 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
今晚搞了一晚上,没有什么进展,特来向大家求教:
ShockWaveFlash控件的IViewObject->Draw()函数在HDC上绘图,屏幕色深为32位时,可以正确绘制带有Alpha通道的图形,当屏幕色深调整为16位的时候,同样代码,Draw()函数得到的图形的Alpha通道内容不正确。

问有没有办法设置DC信息,让依赖于DC信息的函数在16位色深模式下,认为hdc是在32位颜色深度模式,从而得到正确的结果?

(现在是使用vs2008在一个对话框中插入flash控件,并设置WMode为Transparent,
重写对话框的OnPaint函数:
void Ctemp03Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
// CDialog::OnPaint();
CPaintDC dc(this);
RECT rcTotal;
::GetClientRect(m_hWnd, &rcTotal);
BITMAPINFOHEADER bih = { 0 };
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = rcTotal.right - rcTotal.left;
bih.biHeight = (rcTotal.bottom - rcTotal.top); // use screen axis
bih.biPlanes = 1;
bih.biBitCount = 32;
bih.biCompression = BI_RGB;
HDC hdcBack = CreateCompatibleDC ( 0 );
char *m_lpBitsOnly = 0;
HBITMAP bmpBack = CreateDIBSection( 0, (PBITMAPINFO)&bih, DIB_RGB_COLORS, (void **)&m_lpBitsOnly, NULL, 0x0);
HGDIOBJ hOldObj = ::SelectObject(hdcBack, bmpBack);
CDC hello;
hello.Attach(hdcBack);
PaintWindowlessControls(&hello);
BLENDFUNCTION blendFunc = {AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
::AlphaBlend(dc.GetSafeHdc(), 0, 0, bih.biWidth, bih.biHeight, hdcBack, 0, 0, bih.biWidth, bih.biHeight, blendFunc );
::SelectObject(hdcBack, hOldObj);
::DeleteObject(bmpBack);
//FILE *f = fopen("d:\\b.bin", "wb");
//fwrite(m_lpBitsOnly, 1, bih.biWidth*bih.biHeight*4, f);
//fclose(f);
//}
}
}

这样在16位色深屏幕下面,得到的结果不正确。

使用gimp以Raw Image模式打开注释掉的写文件代码产生d:\b.bin文件,可以明确看到,16bit color模式下,alpha通道全部为零,显然不是需要的结果,而在32bit color模式下面,alpha通道没有问题。)
...全文
评论 22
收藏 已收藏
分享
返回顶部
sunlin7
界面 15,976 成员 115,866 内容