在代码中嵌入图片,而不使用资源节或外部图片 [英] Embed image in code, without using resource section or external images

查看:86
本文介绍了在代码中嵌入图片,而不使用资源节或外部图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种在图书馆中嵌入图片的方法(仅限Windows)。我不想以传统的方式把它放在资源(因为特殊的情况下,使它不那么方便的资源句柄混乱。)

I'm looking for a way to embed an image in a library (Windows-only). I don't want to go the 'traditional' way of putting it in the resources (because of special circumstances that make it not so convenient to mess around with the resource handle.

理想情况下,会有类似xpm文件的东西:一个放在ac数组中的图像的'文本'表示,一些代码转换为内存中的位图,然后以某种方式加载到HIMAGE或HICON。我想要嵌入的图像是32位的位图(bmp)。任何想法?我使用MFC,所以一个MFC库会很好,但我当然可以使用一个库,不使用MFC太感谢。 / p>

Ideally, there would be something like xpm files: a 'text' representation of an image that is put in a c array and that some code converts into a bitmap in memory, which can then somehow be loaded into an HIMAGE or an HICON. The images I want to embed are 32-bit bitmaps (bmp). Any ideas? I'm using MFC so an MFC library would be fine, but of course I can use a library that doesn't use MFC too. Thanks.

推荐答案

Google for a bin2c utility(like like http://stud3.tuwien.ac.at/~e0025274/bin2c/bin2c.c )。它需要一个文件的二进制表示,并输出一个C源文件,包括

Google for a bin2c utility (something like http://stud3.tuwien.ac.at/~e0025274/bin2c/bin2c.c). It takes a file's binary representation and spits out a C source file that includes an array of bytes initialized to that data.

只需将文件链接起来,您的图片就位于一块内存中。

Just link the file in and you have your image sitting in a chunk of memory.

使用这种工具在嵌入式系统中非常常见,例如资源甚至文件可能不存在。

Using this kind of tool is really common on embedded systems where such things as 'resources' and even files might not exist.

这篇关于在代码中嵌入图片,而不使用资源节或外部图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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