I have a JavaFX app that loads image files and performs certain manipulations on them. I recently became aware of a problem in which on Windows machines, the app won’t load and process images that have non-English letters in the filepaths (ex. å, ü, ó).
I’m assuming it’s an encoding issue, but I’m having difficult nailing down where in the workflow to do a conversion. Of note, this only happens on Windows. Works fine on Mac, I’m assuming due to differences in the OS’s default encoding. This also makes it painstakingly slow to diagnose, as my IDE is on a Mac.
For example, here’s a short bit of code in the load function, with some debugging inserted in an attempt to diagnose where the issue is first arising.
if (file != null) {
try {
//Get filename parts
String[] fileComponents = FileChooserClass.FilePathComponents(file);
String filepath = fileComponents[0];
loadDebug2(filepath); // dialog window showing the filepath
//Create a Mat of the image
Mat originalMat = new Mat();
try {
originalMat = Imgcodecs.imread(filepath); //fails here
loadDebug(originalMat); //if properly read from filepath, show stage displaying the image
} catch (Exception e) {
loadDebug2("exception"); //dialog to let me know if there was an exception in loading the image to a mat
}
Using this short bit of code as an example, the filepath is properly shown in the debug dialog window, complete with diatric characters.
However, the mat isn’t properly created from the filepath, and the exception dialog is triggered instead.
It’s as if the app can’t find the source file because of the encoding, but the filepath is displayed properly with the diatric characters.
Anyone have any ideas on how best to handle the encoding?