saddam
saddam

Reputation: 196

How to convert Image Data type from imageUrl

I need to convert this watermark(from assets) image and imageurl(getting from API) to Image data type, because ui.drawImage takes only Image data types

 ui.Image? watermarkImage = ui.decodeImage('assets/images/watermark.png');// getting error
    ui.Image? lookbookImage = ui.decodeImage(imageurl); // getting error
    final originalImage = imgData;
    ui.Image image = ui.Image(160, 50);
    ui.drawImage(image, watermarkImage);

Upvotes: 0

Views: 657

Answers (1)

Mohammed Alfateh
Mohammed Alfateh

Reputation: 3514

First you need to get the image bytes

// network
final response = await http.Client().get(Uri.parse(imageurl));
final bytes = response.bodyBytes;

//assets
final byteData = await rootBundle.load('assets/images/watermark.png');
final bytes = byteData.buffer.asUint8List();

Then you can decode ui.Image from the image bytes


final image = await decodeImageFromList(bytes);

Upvotes: 1

Related Questions