从内存中检索图像数据
我正在使用 FreeImage 库来处理加载图像并将它们传递给 OpenGL。目前,我支持从文件中读取图像。但是,我想将其扩展为能够读取变量以用于游戏内容包。基本上,简而言之,我将整个文件、标头和所有内容写入 unsigned char *。我想获取这个缓冲区并用它做类似的事情(假设声明了变量 fif):
FIBITMAP * dib = FreeImage_Load(fif, "someImage.png");
但我想指定 unsigned char * 而不是 someImage.png (为了解决问题,让我们将其称为缓冲区)。库中有没有可以处理这样的事情的方法?
编辑:考虑到“someImage.png”可以被视为 unsigned char *,我应该更具体一些。
为了消除混淆(如果有的话),unsigned char * buffer 的值将由类似以下伪代码的内容确定:
fileStream = openFile "someImage.png"
unsigned char * buffer = fileStream.ReadToEnd
I'm using the FreeImage Library to handle loading images and passing them to OpenGL. Currently, I have support for reading an image from a file. However, I'd like to extend this to being able to read from a variable for the purpose of game content packages. Basically, in short, I have the entire file, header and all, written to an unsigned char *. I want to take this buffer and do something similar to this with it (assume variable fif is declared):
FIBITMAP * dib = FreeImage_Load(fif, "someImage.png");
but instead of someImage.png, I want to specify the unsigned char * (lets call it buffer for the sake of the question). Is there a method in the library that can handle such a thing?
EDIT: I should be a bit more specific considering "someImage.png" can be considered an unsigned char *.
To clear confusion up, if any, the value of unsigned char * buffer would be determined by something like this psuedo code:
fileStream = openFile "someImage.png"
unsigned char * buffer = fileStream.ReadToEnd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您想使用 FreeImage_ConvertToRawBits。这是文档中的示例:
It sounds like you want to use FreeImage_ConvertToRawBits. Here is an example from the documentation:
使用FreeImage_LoadFromHandle。您需要创建 3 个可以访问缓冲区的函数,并将这些函数的地址放入 FreeImageIO 结构中。
Use
FreeImage_LoadFromHandle
. You'll need to create 3 functions that can access the buffer, and put the addresses of those functions in a FreeImageIO structure.