我创建了一个示例应用程序,使用flutter将容器另存为图像。这与android设备完全正常工作,并且保存的图像质量良好。但是,当我在iPhone(仿真器和物理设备)中进行检查时,保存的图像质量不好。
下面是我用来将容器另存为图像的代码,我只是传递了需要保存的容器的全局密钥。
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:ui' as ui;
import 'dart:io' as Io;
import 'package:path_provider/path_provider.dart';
import 'package:gallery_saver/gallery_saver.dart';
class ImageExport {
save(GlobalKey globalKey) async {
Random random = new Random();
int randomNumber = random.nextInt(1000);
RenderRepaintBoundary boundary =
globalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage(pixelRatio: 5.0);
final directory = (await getApplicationDocumentsDirectory()).path;
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
Io.File imgFile = new Io.File('$directory/test$randomNumber.jpg');
imgFile.writeAsBytes(pngBytes);
imgFile.writeAsBytesSync(pngBytes);
GallerySaver.saveImage(imgFile.path, albumName: "test");
}
}
能帮我解决这个问题吗?