You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running on Flutter web, the TextureLoader doesn't know how to read the dimensions of a PNG image if the TextureLoader.fromBytes constructor is used, thus throwing an exception. #63
I've noticed that when running on flutter web and loading a texture using the TextureLoader.fromBytes constructor, the current algorithm uses the JPEG header (SOI marker) descriptor to figure out the dimensions of the image based on the data in the bytes array. However, if the image is a PNG file, the algorithm does nothing and the ImageElementwidth and height remain at 0, which throws an exception when applying a logarithmic operation on 0.
From my understanding and from what I could find on the web, it seems that it's possible to retrieve the image's dimensions, irrespective of its type (as long as the format is supported) like so:
final codec =await ui.instantiateImageCodec(bytes);
final frameInfo =await codec.getNextFrame();
width = frameInfo.image.width;
height = frameInfo.image.height;
frameInfo.image.dispose();
And the code can be run from both web and mobile.
The documentation of the instantiateImageCodec doesn't say anything about it being an expensive operation, so I assume it's safe to use it in this case.
Furthermore, I haven't found a PNG specification or some code that would be able to retrieve the dimensions of a PNG image from its bytes array (similar to the JPEG code you have), but maybe you will be luckier or maybe you have more insights into this.