从内存中检索图像数据

发布于 2024-11-17 07:56:51 字数 568 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甲如呢乙后呢 2024-11-24 07:56:51

听起来您想使用 FreeImage_ConvertToRawBits。这是文档中的示例:

   // this code assumes there is a bitmap loaded and
   // present in a variable called ‘dib’
   // convert a bitmap to a 32-bit raw buffer (top-left pixel first)
   // --------------------------------------------------------------
   FIBITMAP *src = FreeImage_ConvertTo32Bits(dib);
   FreeImage_Unload(dib);
   // Allocate a raw buffer
   int width = FreeImage_GetWidth(src);
   int height = FreeImage_GetHeight(src);
   int scan_width = FreeImage_GetPitch(src);
   BYTE *bits = (BYTE*)malloc(height * scan_width);
   // convert the bitmap to raw bits (top-left pixel first)
   FreeImage_ConvertToRawBits(bits, src, scan_width, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE);
   FreeImage_Unload(src);
   // convert a 32-bit raw buffer (top-left pixel first) to a FIBITMAP
   // ----------------------------------------------------------------
   FIBITMAP *dst = FreeImage_ConvertFromRawBits(bits, width, height, scan_width, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, FALSE);

It sounds like you want to use FreeImage_ConvertToRawBits. Here is an example from the documentation:

   // this code assumes there is a bitmap loaded and
   // present in a variable called ‘dib’
   // convert a bitmap to a 32-bit raw buffer (top-left pixel first)
   // --------------------------------------------------------------
   FIBITMAP *src = FreeImage_ConvertTo32Bits(dib);
   FreeImage_Unload(dib);
   // Allocate a raw buffer
   int width = FreeImage_GetWidth(src);
   int height = FreeImage_GetHeight(src);
   int scan_width = FreeImage_GetPitch(src);
   BYTE *bits = (BYTE*)malloc(height * scan_width);
   // convert the bitmap to raw bits (top-left pixel first)
   FreeImage_ConvertToRawBits(bits, src, scan_width, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE);
   FreeImage_Unload(src);
   // convert a 32-bit raw buffer (top-left pixel first) to a FIBITMAP
   // ----------------------------------------------------------------
   FIBITMAP *dst = FreeImage_ConvertFromRawBits(bits, width, height, scan_width, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, FALSE);
滥情稳全场 2024-11-24 07:56:51

使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文