Convert uint8list image to a supported Image file(jpg or etc.)
Asked Answered
E

1

7

In android 10 and 11 (SDK number 29 and 30) music covers (artworks) formats aren't the same as previous versions, in fact, they aren't readable as a supported image file such as jpg or png, they are uint8lists and only Image.memory widget accepts and shows them.

Now, my problem is I don't wanna read them as a memory image, I need files such as jpg or etc.

Searched a lot! Read a lot and found only 1, not working solution! And that was writing unit8list as bytes in a file which it's path is ended with ".jpg". As I said it's not working.

Anyone can help?

Thanks in advance, <3.

final io.File image = File('directory/image.jpg').create();
image.writeAsBytesSync(uint8list);

uint8list sample:[255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 226, 2, 40, 73, 67, 67, 95, 80, 82 ,...]

length: thousands

Erbil answered 28/12, 2020 at 7:28 Comment(9)
"they are uint8lists" - how you read them? what is their magic number?Cuprite
#53078993 you can read to resultBonus
@Bonus I guess you misunderstood my question! I wanna decode unit8list to jpg not encode it!Erbil
@Cuprite I don't know a lot about uint8lists and only know that it's an encoding method to compress images as a string data.Erbil
@Cuprite Flutter_audio_query package provides them.Erbil
I'll provide a sample of uint8list in edit.Erbil
@Cuprite sample of uint8list added.Erbil
your uint8list is a valid image data, if Image.memory can decode it then Image.file will do work too if you write your data correctlyCuprite
Have you checked my answer if this could help?Patronize
W
7

To write Uint8list as a file, you can use File(String).writeAsBytes(Uint8list);. You can set the path and file extension on the File object and pass the image bytes on writeAsBytes()

Uint8List imageBytes;
File('image.jpg').writeAsBytes(imageBytes);
Welford answered 21/1, 2022 at 1:7 Comment(5)
you have any idea, how to write Uint8List as Image data type in flutterAttenuator
If you're pertaining to the Image widget, you can use Image.memory(Uint8List)Welford
No, I'm not using that in widget..Attenuator
How did you know the format of the image, that you want to end the the path with like .jpg .png...etc.Selfexpression
this one works but you need to assign a complete path not just image name.Papillose

© 2022 - 2024 — McMap. All rights reserved.