我有一张从画布PictureRecorder
得到的图像。现在我想把它上传到Firebase存储。我的问题是将其转换为png文件进行上传。我不太知道如何转换图像,所以不确定如何操作它,以一种方式上传为png文件。
final picture = recorder.endRecording();
final img = picture.toImage(640, 360);
final pngBytes = await img.toByteData();
final Directory systemTempDir = Directory.systemTemp;
final File file = await new File('${systemTempDir.path}/foo.png').create();
file.write?????(pngBytes); <-- Not sure how to write the file here
final StorageReference ref =
storage.ref().child('images').child('image.png');
final StorageUploadTask uploadTask =
ref.putFile(file);
发布于 2018-05-14 23:54:49
明白了!
final picture = recorder.endRecording();
final img = picture.toImage(640, 360);
final pngBytes = await img.toByteData(format: ImageByteFormat.png);
Uint8List finalImage = Uint8List.view(pngBytes.buffer);
final Directory systemTempDir = Directory.systemTemp;
final File file = await new File('${systemTempDir.path}/foo.png').create();
file.writeAsBytes(finalImage);
final StorageReference ref = storage.ref().child('images').child('image.png');
final StorageUploadTask uploadTask = ref.putFile(file);
发布于 2018-05-14 19:36:35
您可以使用imagemagik进行文件转换。This link为您提供了大量关于如何做到这一点的详细信息,因此我不会在此赘述。或者,您可以使用could write a cloud function在服务器上执行转换。这取决于您的用例。
HTH。
https://stackoverflow.com/questions/50337558
复制