Image 保存后PNG图像背景变黑

Image 保存后PNG图像背景变黑,image,flutter,dart,png,Image,Flutter,Dart,Png,潜在副本:尝试了解决方案,但无效 我正在用flutter开发一个图像着色应用程序,它可以让用户给一个黑色的轮廓图像着色并保存它 现在我下载了很多PNG图片,这些图片看起来很普通,但一旦添加到Flatter assets文件夹中,就会显示黑色的平铺背景 一旦添加到允许用户选择所需图像的gallery屏幕,应用程序将显示完全正常的图像。但是在我保存图像时,给图像着色后,我看到一个黑色背景 这里有一个打开的vs代码 **这是图像选择屏幕,显示了一只完全正常的鸟:** 保存后的图像如下: 现在是编

潜在副本:尝试了解决方案,但无效

我正在用flutter开发一个图像着色应用程序,它可以让用户给一个黑色的轮廓图像着色并保存它

现在我下载了很多PNG图片,这些图片看起来很普通,但一旦添加到Flatter assets文件夹中,就会显示黑色的平铺背景

一旦添加到允许用户选择所需图像的gallery屏幕,应用程序将显示完全正常的图像。但是在我保存图像时,给图像着色后,我看到一个黑色背景

这里有一个打开的vs代码

**这是图像选择屏幕,显示了一只完全正常的鸟:**

保存后的图像如下:

现在是编码部分

这是我的显示图像部分:

Widget displayImage(BuildContext context, String providedImagePath) {
    return Container(
      // child: Container(
      //   decoration: BoxDecoration(
      //     color: Colors.white,
      //   ),
      child: Image(
        image: AssetImage(providedImagePath),
        // color: Color.fromRGBO(255, 255, 255, 1.0),
        colorBlendMode: BlendMode.modulate,
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
      ),
      //),
    );
注释输出部分来自其他堆栈溢出答案,我尝试过,但没有成功

下面是保存功能:

  Future<void> _save() async {
    RenderRepaintBoundary boundary =
        globalKey.currentContext.findRenderObject();
    ui.Image image = await boundary.toImage();
    ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    Uint8List pngBytes = byteData.buffer.asUint8List();

    //Request permissions if not already granted
    if (!(await Permission.storage.status.isGranted))
      await Permission.storage.request();

    final result = await ImageGallerySaver.saveImage(
        Uint8List.fromList(pngBytes),
        quality: 60,
        name: "henlo");
    print(result);
  }
Future\u save()异步{
渲染边界=
globalKey.currentContext.FindEnderObject();
ui.Image=wait boundary.toImage();
ByteData ByteData=等待image.toByteData(格式:ui.ImageByteFormat.png);
Uint8List pngBytes=byteData.buffer.asUint8List();
//请求权限(如果尚未授予)
如果(!(等待权限。存储。状态。已授予))
等待权限.storage.request();
最终结果=等待ImageGallerySaver.saveImage(
Uint8List.fromList(PNGB字节),
质量:60,
名称:“亨洛”);
打印(结果);
}

可能介于

boundary.toImage();

我不确定是什么原因导致了这个问题,但是你可以再次删除背景,作为一种解决方法来尝试

byteData.buffer.asUnit8List();