我正在嘗試使用 SDL2-image 加載影像,當我嘗試加載 .png 時它可以作業,但無法識別 .jpg
我的進口:
#include <SDL2/SDL.h>
#undef main
#include <SDL2/SDL_image.h>
#include "logger.hpp"
我的代碼:
int main(int argc, char **argv) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
logger::Log(logger::DEBUG, "Could not initialize SDL (%s)", SDL_GetError());
}
int flags = IMG_INIT_JPG | IMG_INIT_PNG;
int initRes = IMG_Init(flags);
if (initRes & flags != flags) {
logger::Log(logger::DEBUG, "IMG_Init: Failed to init required jpg and png support!");
logger::Log(logger::DEBUG, "IMG_Init: %s", IMG_GetError());
}
else logger::Log(logger::DEBUG, "JPG AND PNG SUPPORTED");
SDL_Surface* surface = IMG_Load("image.jpg");
if (!surface) {
logger::Log(logger::DEBUG, "surface error: %s", IMG_GetError());
}
else {
logger::Log(logger::DEBUG, "LOADED");
}
...
}
這給了我
JPG AND PNG SUPPORTED
surface error: Unsupported image format
有通過vcpkg安裝和集成:SDL2-image、libjpeg-turbo、libpng和zlib,所以我基本上不知道為什么會這樣
uj5u.com熱心網友回復:
由于運算子優先級initRes & flags != flags等價于initRes & (flags != flags)which 將始終為假。你需要(initRes & flags) != flags改用。
Jpeg 支持是一項可選功能,您需要啟用libjpeg-turbo.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/472990.html
