使用 CxImage 绘制透明/alpha 图像
我正在尝试使用 CxImage 绘制透明(alpha)PNG 图像,但似乎我缺少一些明显的步骤...到目前为止的代码是:
CxImage image(m_pImage, m_lSize, CXIMAGE_FORMAT_UNKNOWN);
CRect rcOut = rc;
rcOut.left = (rc.Width()/2) - (image.GetWidth()/2);
rcOut.right = rcOut.left + image.GetWidth();
rcOut.top = (rc.Height()/2) - (image.GetHeight()/2);
rcOut.bottom = rcOut.top + image.GetHeight();
image.Draw(dc.GetSafeHdc(),rcOut);
m_pImage 在其他地方加载,使用:
CxImage image(strPath,CXIMAGE_FORMAT_UNKNOWN);
long lSize = 0;
BYTE * pBuf = NULL;
RGBQUAD rgbq;
rgbq.rgbRed = 255;
rgbq.rgbGreen = 255;
rgbq.rgbBlue = 255;
rgbq.rgbReserved = 0;
image.Thumbnail(paramImageSize, paramImageSize, rgbq);
image.SetJpegQuality(100);
image.Encode(pBuf, lSize, CXIMAGE_FORMAT_JPG);
你能看到我缺少什么吗?
提前致谢!
I am trying to draw a transparent (alpha) PNG image using CxImage, but it seems I'm missing some obvious step... The code so far is:
CxImage image(m_pImage, m_lSize, CXIMAGE_FORMAT_UNKNOWN);
CRect rcOut = rc;
rcOut.left = (rc.Width()/2) - (image.GetWidth()/2);
rcOut.right = rcOut.left + image.GetWidth();
rcOut.top = (rc.Height()/2) - (image.GetHeight()/2);
rcOut.bottom = rcOut.top + image.GetHeight();
image.Draw(dc.GetSafeHdc(),rcOut);
where m_pImage is loaded elsewhere using:
CxImage image(strPath,CXIMAGE_FORMAT_UNKNOWN);
long lSize = 0;
BYTE * pBuf = NULL;
RGBQUAD rgbq;
rgbq.rgbRed = 255;
rgbq.rgbGreen = 255;
rgbq.rgbBlue = 255;
rgbq.rgbReserved = 0;
image.Thumbnail(paramImageSize, paramImageSize, rgbq);
image.SetJpegQuality(100);
image.Encode(pBuf, lSize, CXIMAGE_FORMAT_JPG);
Can you see what I'm missing?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 Thumbnail() 函数以及目标格式为 JPEG 导致了这些问题。 改成Resample2()和PNG就可以了。
It seems that the Thumbnail() function caused those problem along with the destination format being JPEG. Changed to Resample2() and PNG and it's ok.