【发布时间】:2021-06-29 23:40:55
【问题描述】:
Question 的潜在副本:尝试了解决方案但没有用
我正在开发一个 Flutter 中的图像着色应用程序,它允许用户为黑色轮廓图像着色并保存它。
现在我已经下载了相当多的 PNG 图片,这些图片看起来很正常,但一旦添加到颤振资产文件夹中,就会显示黑色平铺背景。
一旦添加到 图库 屏幕,用户可以选择他们想要的任何图像,应用程序会显示完全正常的图像。但是在我保存图像时为图像着色后,我看到黑色背景。
这是一个在 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);
}
【问题讨论】: