Windows 移动 (MFC)。如何将带有 alpha 通道的图像从 CImageList 转换为 CBitmap?
我对 CBitmapButton 进行了子类化,以使用重写的函数 DrawItem 创建自己的按钮。以下是它的代码,它可以工作:
CDC *pDC = &dc;
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap m_Bmp;
m_Bmp.LoadBitmap(IDB_ARROW);
CBitmap *temp = memDC.SelectObject(&m_Bmp);
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = 255;
AlphaBlend(pDC->m_hDC, pt.x, pt.y, 85, 85, memDC.m_hDC, 0, 0, 85, 85, blend);
dc.SelectObject(&temp);
问题是所有图像都已加载并存储在 CImageList 中。而且我不知道如何转换它们。
CImageList 创建过程中可能出现问题: m_LargeImg.Create(365, 85, ILC_COLOR32, 4, 0);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON1, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON2, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON3, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON4, &m_LargeImg);
I have subclassed CBitmapButton to create my own button with an overrided function DrawItem. Here is the code from it and it works:
CDC *pDC = &dc;
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap m_Bmp;
m_Bmp.LoadBitmap(IDB_ARROW);
CBitmap *temp = memDC.SelectObject(&m_Bmp);
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = 255;
AlphaBlend(pDC->m_hDC, pt.x, pt.y, 85, 85, memDC.m_hDC, 0, 0, 85, 85, blend);
dc.SelectObject(&temp);
The problem is that all the images are already loaded and stored in CImageList. And I don't know how to convert them.
Maybe something wrong in CImageList creation:
m_LargeImg.Create(365, 85, ILC_COLOR32, 4, 0);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON1, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON2, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON3, &m_LargeImg);
ImageWork::get().addBitmapToList(IDB_MAIN_MENU_ICON4, &m_LargeImg);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,也许你不应该尝试转换它们。如果您只想抓取它们,请尝试使用图像列表绘制函数之一,例如 CImageList::DrawIndirect,它支持 Alpha 混合等。这可能是您唯一需要的东西。
Well, maybe you shouldn't try to convert them. If you just want to craw them, try using one of the image list draw functions like CImageList::DrawIndirect which supports Alpha blending and such. It might be the only thing you need.