-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decodeImageFile error #636
Comments
Yeah, that's a fine suggestion. I just had that file open for another issue, so I pushed that change out. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a jpg file, but it's named "xx.png", when I try decode this file , I using
decodeImageFile("xx.png");
. But get a null .I check the code of
decodeImageFile
, it will get decoder by file name atfindDecoderForNamedImage
, in my case, it will use pngDecoder, of course it a mistake.I find in pngDecoder, it will check file header:
If not png header, will return null.
So, why don't try another decoder if file header not match file name's extension?
Like change:
Future<Image?> decodeImageFile(String path, {int? frame}) async { final bytes = await readFile(path); if (bytes == null) { return null; } final decoder = findDecoderForNamedImage(path); if (decoder != null) { - return decoder.decode(bytes, frame: frame); } return decodeImage(bytes, frame: frame); }
To:
Future<Image?> decodeImageFile(String path, {int? frame}) async { final bytes = await readFile(path); if (bytes == null) { return null; } final decoder = findDecoderForNamedImage(path); if (decoder != null) { + return decoder.decode(bytes, frame: frame) ?? decodeImage(bytes, frame: frame); } return decodeImage(bytes, frame: frame); }
How about it?
The text was updated successfully, but these errors were encountered: