加载位图作为Windows资源时,有没有一种方法,以preserve的BITMAPFILEHEADER? [英] Is there a way to preserve the BITMAPFILEHEADER when loading a Bitmap as a Windows resource?

查看:184
本文介绍了加载位图作为Windows资源时,有没有一种方法,以preserve的BITMAPFILEHEADER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试一些东西出来使用 SFML 1.4 (简单快速的多媒体库)与C ++和Visual C ++ 2008例preSS版。为了避免与我的图形程序外部图像,我测试了<一个href=\"http://www.sfml-dev.org/documentation/1.4/classsf%5F1%5F1Image.htm#72565ffabe12dfb2602e209c2e6f0486\"相对=nofollow> SF ::图像:: LoadFromMemory(为const char *的数据,性病::为size_t SizeInBytes)与位图资源功能使用一个简单的资源脚本加载:

I've been working on testing a few things out using SFML 1.4 (Simple and Fast Multimedia Library) with C++ and Visual C++ 2008 Express Edition. To avoid having external images with my graphical programs, I was testing out the sf::Image::LoadFromMemory(const char * Data, std::size_t SizeInBytes) function with Bitmap resources loaded using a simple resource script:

IDB_SPRITE BITMAP "sprite1.bmp"

在我的code加载图像以创建的 SF ::图片使用此位图资源,我用下面的方法,包括Win32 API函数(我已经排除了code,检查以确保Win32函数不返回NULL缩短这一点):

In my code to load the image to create an sf::Image using this bitmap resource, I use the following procedure, consisting of Win32 API functions (I've excluded the code that checks to make sure the Win32 functions don't return NULL to shorten this a bit):

HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDB_SPRITE), RT_BITMAP);
HGLOBAL hResData = LoadResource(NULL, hResInfo);
char * resourceData = reinterpret_cast<char *>(LockResource(hResData));

在这之后,我用的是SF ::图像:: LoadFromMemory功能:

After that, I use the sf::Image::LoadFromMemory function:

MyImage.LoadFromMemory(resourceData, SizeofResource(NULL, hResInfo));

但是,这并不工作(我得到一个未知的文件类型错误)。经过一些测试,我发现我传递给LoadFromMemory功能的位图数据不包括BITMAPFILEHEADER(第一个14个字节),而我相信这是对未知文件类型错误的原因。

However, this doesn't work (I get an unknown file type error). After some testing, I discovered that the bitmap data I pass to the LoadFromMemory function does not include the BITMAPFILEHEADER (the first 14 bytes), and I believe this is the cause of the unknown file type error.

我可以手动恢复BITMAPFILEHEADER并获得LoadFromMemory功能很好地工作。 不过,我想知道是否有某种方式来preserve在资源数据的BITMAPFILEHEADER避免这样做呢?

I can restore the BITMAPFILEHEADER manually and get the LoadFromMemory function to work fine. However, I'm wondering if there is some way to preserve the BITMAPFILEHEADER in the resource data to avoid doing this?

推荐答案

使用自定义资源类型将preserve整个文件。更改资源脚本以利用RCDATA类型,而不是位图类型:

Using a custom resource type will preserve the entire file. Change the resource script to utilize the RCDATA type as opposed to the BITMAP type:

IDB_SPRITE RCDATA "sprite1.bmp"

在FindResource函数调用,使用RT_RCDATA代替RT_BITMAP:

In the FindResource function call, use RT_RCDATA instead of RT_BITMAP:

HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDB_SPRITE), RT_RCDATA);

有关详细信息:

RCDATA资源

资源类型

这篇关于加载位图作为Windows资源时,有没有一种方法,以preserve的BITMAPFILEHEADER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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