1

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.

demonplus
  • 5,613
  • 12
  • 49
  • 68

2 Answers2

1

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.

demonplus
  • 5,613
  • 12
  • 49
  • 68
  • Thanks. His article could be slightly simpler by letting CreateStreamOnHGlobal handle the memory and using CImage::Load (since LoadFromResource will not load jpg's). – gast128 Oct 15 '21 at 09:13
0

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

Goz
  • 61,365
  • 24
  • 124
  • 204
  • 1
    JPEG is the name of custom category in resources, it can't influence creating of bitmap from stream. But anyway I tried your suggestion - it didn't help. – demonplus Sep 30 '10 at 18:39