-1

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.

Dalton
  • 181
  • 1
  • 8

1 Answers1

3

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 MFC CImageList 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.

AJG85
  • 15,849
  • 13
  • 42
  • 50
  • Thank you, my English is actually no very good. I was sleepy and could able to write many information. Please explain slowly or I unable to catch you. I test what you tell me and it is not right. The return value of Add function is not -1. And my Create function is hide in OninitialUpdate, like this **m_imglst.Create(100,100,ILC_COLOR32,0,1);** – Dalton Aug 10 '11 at 04:25
  • I'm not going to keep guessing at what your problem might be but you can take a look at what I did for a similar problem: http://stackoverflow.com/questions/4598872/creating-hbitmap-from-memory-buffer – AJG85 Aug 10 '11 at 16:06
  • check the return value of Add(...) is the key point, make sure image is added into CImageList – hcnak May 12 '19 at 12:37