CListCtrl和缩略图绘制失败
我使用以下代码为加载大图像的列表控件创建缩略图
HDC hDC=::GetDC(hWnd);
HDC pDC=::CreateCompatibleDC(hDC);
HBITMAP bm=::CreateCompatibleBitmap(hDC,THUMBNAIL_W,THUMBNAIL_H);
HBITMAP oldBmp=(HBITMAP)SelectObject(pDC,bm);
img.StretchBlt(pDC,rcBorder);
CBitmap bmp;
bmp.Attach(bm);
m_imgLst.Add(&bmp,RGB(0,0,0));
存储在 CImage 中
,它作为CImage img
;但缩略图是黑色的,没有绘制任何内容
上面的代码
img.StretchBlt(pDC,rcBorder); 什么也没做。
I use the folow code to create a thumbnail for list control
HDC hDC=::GetDC(hWnd);
HDC pDC=::CreateCompatibleDC(hDC);
HBITMAP bm=::CreateCompatibleBitmap(hDC,THUMBNAIL_W,THUMBNAIL_H);
HBITMAP oldBmp=(HBITMAP)SelectObject(pDC,bm);
img.StretchBlt(pDC,rcBorder);
CBitmap bmp;
bmp.Attach(bm);
m_imgLst.Add(&bmp,RGB(0,0,0));
a big image is load, it is store in CImage as
CImage img;
but the thumbnail is black, nothing is drawn
the above code
img.StretchBlt(pDC,rcBorder);
doesn't do a thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个不完整且措辞不当的问题。混合和匹配 Windows API、MFC 和 GdiPlus 很好,但如果没有提供足够的相关代码或解释,任何人都可以做的就是猜测您的问题。
这就是我的猜测。黑色位图的症状通常意味着您的位深度错误。我不知道您正在使用
CImage
做什么,但上面的代码看起来不错,尽管缺少对调用的 API 的成功验证。我将进一步假设
m_imgLst
是一个 MFCCImageList
对象,在这种情况下,可能的错误出现在该对象上其他位置的.Create
调用中您现在尝试添加的图像的位深度或尺寸不兼容。您可以通过检查
.Add
的返回值来测试我的理论,它应该是新插入图像的索引,如果失败则为 -1。This is an incomplete and poorly worded question. Mixing and matching Windows API, MFC, and GdiPlus is fine but without giving enough relevant code or explanation all anyone can do is guess at your problem.
That said here's my guess. The symptom of a black bitmap usually means your bit depth was wrong. I have no idea what you are doing with
CImage
but the code above looks fine albeit missing any validation of success on the API called.I'll further assume that
m_imgLst
is an MFCCImageList
object in which case a likely mistake was in the.Create
call elsewhere on that object with an incompatible bit depth or dimensions for the image you are now trying to add.You can test my theory by checking the return value of
.Add
it should be the index of the newly inserted image or -1 if it fails.