【问题标题】:SDL IMG_Load() on Mac and Linux return different BitsPerPixel for same imageMac 和 Linux 上的 SDL IMG_Load() 为同一图像返回不同的 BitsPerPixel
【发布时间】:2013-09-06 10:56:43
【问题描述】:

我正在使用 SDL 的 IMG_Load() 函数在 Linux 和 Mac OS X 上加载 PNG 文件。它可以工作,但奇怪的是,在 Linux 上我得到了 24 BitsPerPixel 和 OS X 上的格式32 bpp。

SDL_Surface *image = IMG_Load("path/to/image.png");
std::cerr << (int)image->format->BitsPerPixel << std::endl;

两个系统上的图像文件完全相同。

$ file data/test_scenario.png
data/test_scenario.png: PNG image data, 640 x 400, 8-bit/color RGB, non-interlaced

从文件输出来看,我认为 24​​bpp 是正确的。

知道为什么会发生这种情况以及如何避免这种情况吗?

【问题讨论】:

    标签: c++ linux image macos sdl


    【解决方案1】:

    image 是一个新表面,不保证与原始.png 具有相同的 bpp。

    如果您只需要从.png 打印格式信息,我应该很容易使用自定义函数或至少使用libpng 访问标题。

    如果你需要 blit 加载图片,你有两个选择:

    • 支持应用中需要的两种 bpp 格式
    • 使用所需的 bpp 创建一个新表面,并在加载后转换 image

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 2015-05-04
      • 1970-01-01
      相关资源
      最近更新 更多