Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save a memory image (such as Uint8list) as image file in flutter

I have some Uint8lists and I wanna save them as jpg files. I searched a lot for this on the web but found nothing! Anyone can help?

Thanks,

like image 769
M.Taha Basiri Avatar asked Dec 05 '20 07:12

M.Taha Basiri


Video Answer


1 Answers

By 'storage', do you mean write to a file? You don't really need "flutter" to do this. Just use the libraries provided by dart. Here is an example of downloading my gravatar which you can get as Uin8List and then saving it to a file.

import 'dart:io';
import 'dart:typed_data';

import 'package:http/http.dart' as http;

void main() {
  http.get('https://www.gravatar.com/avatar/e944138e1114aefe4b08848a46465589').then((response) {
    Uint8List bodyBytes = response.bodyBytes;
    File('my_image.jpg').writeAsBytes(bodyBytes);
  });
}
like image 101
lsiu Avatar answered Oct 16 '22 14:10

lsiu