颤振:将图像上载到Firebase存储
我有一张从画布颤振:将图像上载到Firebase存储,firebase,dart,image-uploading,flutter,firebase-storage,Firebase,Dart,Image Uploading,Flutter,Firebase Storage,我有一张从画布图片记录器中获取的图像。现在我想把它上传到Firebase存储。我的问题是将其转换为png文件进行上传。我对转换图像不太了解,所以不知道如何将其作为png文件上传 final picture = recorder.endRecording(); final img = picture.toImage(640, 360); final pngBytes = await img.toByteData(); final Directory systemTempDir = Directo
图片记录器中获取的图像。现在我想把它上传到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);
final picture=recorder.endRecording();
最终img=picture.toImage(640360);
final pngBytes=等待img.toByteData();
最终目录systemTempDir=Directory.systemTemp;
final File File=等待新文件('${systemTempDir.path}/foo.png').create();
文件写入(PNG字节) 您可以使用imagemagik进行文件转换。给你一个合理数量的细节如何做到这一点,所以我不会在这里挖。或者,您也可以选择在服务器上执行转换。取决于您的用例
HTH.您可以使用imagemagik进行文件转换。给你一个合理数量的细节如何做到这一点,所以我不会在这里挖。或者,您也可以选择在服务器上执行转换。取决于您的用例
嗯。明白了
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);
明白了
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);