Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen file name with UTF8 string in windows

When I used opencv's API cvLoadImage(const char *filename, int iscolor) It accepts const char * as file name. When the file name is not ASCII-character, I tried to convert it to UTF8 string. It fails because fopen() called in cvLoadImage() can not interpret the characters of the file name literally as ASCII string. I may used _wfopen() if tried to open file names, but if fopen() is called in the third-party library, is there any method to handle this problem? Thank you.

like image 926
binzhang Avatar asked Dec 09 '22 08:12

binzhang


1 Answers

Use GetShortPathName. It will return an old (8.3) name for the file, which you should be able to convert to char*, as it should not contain any non ASCII characters.

I've just tested it with some language specific characters and it worked as I described. I've successfully opened a file from C:\łęłęł\ąóąóą.tsttgbb using fopen.

like image 168
W.B. Avatar answered Dec 11 '22 10:12

W.B.