从MFC C ++应用程序中的资源加载JPEG文件 [英] Loading JPEG file from resources in MFC C++ application

查看:195
本文介绍了从MFC C ++应用程序中的资源加载JPEG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Windows XP下可以正常工作:

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);

但是在Windows 7中, image.Load 返回 E_FAIL 虽然创建了 CResourceStream 可以正确地从资源读取JPEG文件。

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

调试会得到以下结果:

GdipCreateBitmapFromStream 返回 InvalidParameter

可能是什么问题?

JPEG是资源文件中的自定义类别。

JPEG is a custom category in resource file.

推荐答案

最后,我使用了来自codeproject的此解决方案:

At the end I used this solution from codeproject:

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

它是GDI +的精简包装,能够在Windows下加载JPEG文件(和其他文件)完美地是7。

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

这篇关于从MFC C ++应用程序中的资源加载JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆