我使用以下代码将 PNG 图像加载到图片控件中。
....
LPSTREAM pStrmDefImg = TurnStream(MAKEINTRESOURCE(resourceID),_T("PNG"));
if(pStrmDefImg != NULL) {
CImage img;
img.Load(pStrmDefImg); // Load from stream
pictureCtrl.SetBitmap(img);
pStrmDefImg->Release();
}
.....
LPSTREAM TurnStream(LPCTSTR Resource, LPCTSTR Type)
{
char* pData = 0;
DWORD dwSize = 0;
int nRes = GetResource(Resource,Type,&pData,&dwSize);
LPSTREAM pStream;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwSize+1);
void *pImageData = GlobalLock(hGlobal);
memcpy(pImageData, pData, dwSize);
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
return pStream;
}
您在此代码中看到任何问题吗?没有抛出错误,但图片控件不显示加载的图像。