Loading JPEG file from resources in MFC C++ application

让人想犯罪 __ 提交于 2020-06-17 02:07:28

问题


The following code works correctly under Windows XP:

CImage image;

RECT destRect;

int nResource = 10;

CResourceStream stream(0, MAKEINTRESOURCE(nResource), _T("JPEG")); 

HRESULT hr = image.Load(&stream);

image.Draw(hDC, destRect);

But on Windows 7 image.Load returns E_FAIL though creating CResourceStream reads JPEG file from resources correctly.

Debugging gives the following result:

GdipCreateBitmapFromStream returns InvalidParameter.

What the problem can be?

JPEG is a custom category in resource file.


回答1:


I believe you should use "JPG" not "JPEG".




回答2:


At the end I used this solution from codeproject:

http://www.codeproject.com/KB/GDI-plus/cgdiplusbitmap.aspx

It is a thin wrapper for GDI+ which is able to load JPEG files (and others) under Windows 7 perfectly.



来源:https://stackoverflow.com/questions/3829107/loading-jpeg-file-from-resources-in-mfc-c-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!