简体   繁体   中英

Loading JPEG file from resources in MFC C++ application

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.

我相信您应该使用“ JPG”而不是“ JPEG”。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM