我正在尝试使用Flutter插件“Image”https://pub.dartlang.org/packages/image来调整图像大小。
按照说明书上的方法,我正在使用以下方法:
File resizeMyImage(File resizeThisFile) {
// decodeImage will identify the format of the image and use the appropriate
// decoder.
File myCompressedFile;
Image image = decodeImage(resizeThisFile.readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
// Save the thumbnail as a PNG.
myCompressedFile = new Io.File('thumbnail.png')..writeAsBytesSync(encodePng(thumbnail));
return myCompressedFile;
}
我收到的错误信息
E/flutter (22897): FileSystemException: Cannot open file, path = 'thumbnail.png' (OS Error: Read-only file system, errno = 30)
任何帮助都将不胜感激 - 谢谢。
工作中的调整大小类如下所示。希望能对某些人有所帮助。
import 'dart:async';
import 'dart:io' as Io;
import 'dart:io';
import 'package:image/image.dart';
import 'package:path_provider/path_provider.dart';
class ResizeImage {
String tempPath;
Future main() async {
}
Future<Io.File> resizeMyImage(File resizeThisFile) async {
Directory tempDir = await getTemporaryDirectory();
tempPath = tempDir.path;
// decodeImage will identify the format of the image and use the appropriate
// decoder.
File myCompressedFile;
Image image = decodeImage(resizeThisFile.readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
// Save the thumbnail as a PNG.
print('resizeMyImage............tempPath: '+tempPath);
myCompressedFile = new Io.File(tempPath+'thumbnail.png')..writeAsBytesSync(encodePng(thumbnail));
return myCompressedFile;
}
}