Flutter - Image object from Codec object
Flutter has multiple classes named Image
. Do you actually want a dart:ui
Image
object? If you want an ImageProvider
for use with an Image
widget, you can use MemoryImage
(to get an ImageProvider
) or Image.memory
(to go directly to a widget).
If you do need to use to use dart:ui
's Image
, then you can use (await codec.getNextFrame()).image
.
SomeGuy
Updated on December 19, 2022Comments
-
SomeGuy over 1 year
The Image class documentation states
"To obtain an Image object, use instantiateImageCodec."
The instantiateImageCodec documentation states
"Instantiates an image codec Codec object."
From that it would be reasonable to assume that Codec is a sub-class of Image... Nope! I can't find information anywhere about how to get from a Codec object to an Image object.
What is the functionality that needs to go into my convert function below?
Image convert(Codec c){ ... }
The code I'm trying to use this in is as follows:
static Future<Image> convertBytesToImage(List<int> bytes){ Uint8List list = Uint8List(bytes.length); list.setAll(0, bytes); Future<Codec> codec = instantiateImageCodec(list); // Do something here so that I can return as Future<Image> }
-
SomeGuy about 4 years@pskink - I've edited the question to include some context
-
-
SomeGuy about 4 yearsMemoryImage was the way to go. Everything is working as expected now. Thanks.