How to display a TIFF image in a Flutter app on an Android device?
The question is quite old but i still want to answer it :)
What you can do with the Image Library is to decode the image (whatever it is) and then encode it as a png and then pass it to the Image Widget.
Why PNG??? => in widgets/images.dart it says
/// This only accepts compressed image formats (e.g. PNG). Uncompressed
/// formats like rawRgba (the default format of [dart:ui.Image.toByteData])
/// will lead to exceptions.
Todo: I had to import the Image Library as imgLib otherwise it was colliding with the Image Widget from Flutter...
import 'package:image/image.dart' as imgLib;
....
imgLib.Decoder dec = imgLib.findDecoderForData(response.data);
Image.memory(imgLib.encodePng(dec.decodeImage(response.data)))
Then you have an Image Widget for displaying it on the UI
sjmcdowall
World traveling and technology loving coder at heart. Years of experience in lots of various technologies, but more a jack of all trades master of none (these days). Love doing the NYT Crossword puzzle, reading, and playing guitar.
Updated on December 08, 2022Comments
-
sjmcdowall over 1 year
Our application allows users to set up a library of various types of resources such as PDFs, spreadsheets, etc. I.e. just about any MIME type of document, which we store on S3.
When a user clicks to view any of these resources we basically determine if we are on an iOS device or Android. On iOS we use url_launcher to basically show just about anything.
Android is a bit more complex, but if the mime type is an image we just also use url_launcher. If not we download the file to a local file and invoke the OpenFile package to show the result (if we can).
This works generally pretty good, except for TIFF image types, which don't display natively in the browser...
Is there an easy way to show TIFF images in a full flutter screen (similar to showing it in a browser) on the Android platform? Actually for image/ mime types is there an easier way to show them rather than url_launcher in general?
The other Stack Overflow question about TIFF on Android does not address this issue as that is for a native Android app and this is for Flutter and that solution doesn't lend itself (easily that I can see) to a Flutter application.
-
flutter over 5 yearsI haven't used the package: pub.dartlang.org/packages/image says it supports reading TIFF images
-
sjmcdowall over 5 yearsThe image package is for reading and manipulating TIFF images, not for displaying them in Flutter. Looked at that one already! :)
-
sjmcdowall over 5 years@dharms -- not exactly relevant I don't think. This is for a Flutter app, not a native Android app (per se).
-
-
sjmcdowall almost 3 yearsNicely done! Finally a good answer -- Not sure that library was available "back in the day"!