简体   繁体   English

SDL2加载带有特殊字符的文件

[英]SDL2 loading files with special characters

I got a problem, that is: in a Windows application using SDL2 & SDL2_Image, it opens image files, for later saving them with modifications on the image data. 我遇到一个问题,那就是:在使用SDL2&SDL2_Image的Windows应用程序中,它会打开图像文件,以供以后在图像数据上进行修改后保存它们。 When it opens an image without special characters (like áéíóúñ , say, "buenos aires.jpg" ) it works as intended. 当它打开 没有特殊字符的图像(例如áéíóúñ ,例如“ buenos aires.jpg” )时,它会按预期工作。 But , if there is any special character as mentioned (say, "córdoba.jpg" ), SDL_Image generates an error saying "Couldn't open file". 但是 ,如果提到了任何特殊字符(例如“córdoba.jpg” ),则SDL_Image会生成一个错误消息,提示“无法打开文件”。 Whatever, if i use the std::ifstream flux with the exact file name that i got from the CSV file (redundant, as "córdoba.jpg" or "misi ó nes.jpg"), the ifstream works well... Is it an error using the special characters? 无论如何,如果我使用std :: ifstream的光通量与我从CSV文件中得到了确切的文件名(多余的,因为“córdoba.jpg”或“迷死ónes.jpg”),则ifstream的效果很好...是使用特殊字符会出错吗? UNICODE, UTF, have something to do? UNICODE,UTF有什么关系吗?

A little information about the environment: Windows 10 (spanish, latin american), SDL2 & SDL2_Image (up to date versions), GCC compiler using Mingw64 7.1.0 有关环境的一些信息:Windows 10(西班牙语,拉丁美洲),SDL2和SDL2_Image(最新版本),使用Mingw64 7.1.0的GCC编译器

About the software I'm trying to make: it uses a CSV form, with the names of various states of Argentina, already tried changing encoding on the .CSV. 关于我要制作的软件:它使用CSV格式,带有阿根廷各个州的名称,已经尝试更改.CSV上的编码。 It loads images based on the names found on the CSV, changes them, and saves. 它根据在CSV上找到的名称加载图像,进行更改并保存。
I know maybe I am missing something basic, but already depleted my resources. 我知道也许我缺少一些基本知识,但是已经耗尽了我的资源。

IMG_Load() forwards its file argument directly to SDL_RWFromFile() : IMG_Load()将其file参数直接转发到SDL_RWFromFile()

// http://hg.libsdl.org/SDL_image/file/8fee51506499/IMG.c#l125
SDL_Surface *IMG_Load(const char *file)
{
    SDL_RWops *src = SDL_RWFromFile(file, "rb");
    const char *ext = SDL_strrchr(file, '.');
    if(ext) {
        ext++;
    }
    if(!src) {
        /* The error message has been set in SDL_RWFromFile */
        return NULL;
    }
    return IMG_LoadTyped_RW(src, 1, ext);
}

And SDL_RWFromFile() 's file argument should be a UTF-8 string: SDL_RWFromFile()file参数应为UTF-8字符串:

 SDL_RWops* SDL_RWFromFile(const char* file, const char* mode) 

Function Parameters: 功能参数:

  • file: a UTF-8 string representing the filename to open 文件:UTF-8字符串,表示要打开的文件名
  • mode: an ASCII string representing the mode to be used for opening the file; mode:ASCII字符串,表示用于打开文件的模式; see Remarks for details 详见备注

So pass UTF-8 paths into IMG_Load() . 因此,将UTF-8路径传递到IMG_Load()

C++11 has UTF-8 string literal support built-in via the u8 prefix: C ++ 11通过u8前缀内置了UTF-8 字符串文字支持:

IMG_Load( u8"córdoba.jpg" );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM