Flutter - Extended_image_ 提供程序包错误
Flutter - Extended_image_ provider package error
我正在尝试使用 extended_image_provider 包来编辑照片。当我想将 rawImageData 转换为 Uin8list 时,程序中断。我真的不明白为什么..
这是函数 => 它在 print('out')
之前中断
Future<void> crop([bool test = true]) async {
final ExtendedImageEditorState state = editorKey.currentState!;
final Rect? rect = state.getCropRect();
final EditActionDetails action = state.editAction!;
final double radian = action.rotateAngle;
final bool flipHorizontal = action.flipY;
final bool flipVertical = action.flipX;
print("in--");
final Uint8List img = state.rawImageData;
print("out--");
final ImageEditorOption option = ImageEditorOption();
option.addOption(ClipOption.fromRect(rect!));
option.addOption(FlipOption(horizontal: flipHorizontal, vertical: flipVertical));
if (action.hasRotateAngle) {
option.addOption(RotateOption(radian.toInt()));
}
option.addOption(ColorOption.saturation(sat));
option.addOption(ColorOption.brightness(bright + 1));
option.addOption(ColorOption.contrast(con));
option.outputFormat = const OutputFormat.jpeg(100);
print(const JsonEncoder.withIndent(' ').convert(option.toJson()));
final DateTime start = DateTime.now();
final Uint8List? result = await ImageEditor.editImage(
image: img,
imageEditorOption: option,
);
日志中的错误:
> Unhandled Exception:
> 'package:extended_image_library/src/extended_image_provider.dart':
> Failed assertion: line 34 pos 12: 'cacheRawData': you should set
> [ExtendedImageProvider.cacheRawData] to true, if you want to get
> rawImageData from provider.
如错误消息中所述,只需将 cacheRawData = true
添加到 ExtendedImageProvider
。
我正在尝试使用 extended_image_provider 包来编辑照片。当我想将 rawImageData 转换为 Uin8list 时,程序中断。我真的不明白为什么..
这是函数 => 它在 print('out')
之前中断Future<void> crop([bool test = true]) async {
final ExtendedImageEditorState state = editorKey.currentState!;
final Rect? rect = state.getCropRect();
final EditActionDetails action = state.editAction!;
final double radian = action.rotateAngle;
final bool flipHorizontal = action.flipY;
final bool flipVertical = action.flipX;
print("in--");
final Uint8List img = state.rawImageData;
print("out--");
final ImageEditorOption option = ImageEditorOption();
option.addOption(ClipOption.fromRect(rect!));
option.addOption(FlipOption(horizontal: flipHorizontal, vertical: flipVertical));
if (action.hasRotateAngle) {
option.addOption(RotateOption(radian.toInt()));
}
option.addOption(ColorOption.saturation(sat));
option.addOption(ColorOption.brightness(bright + 1));
option.addOption(ColorOption.contrast(con));
option.outputFormat = const OutputFormat.jpeg(100);
print(const JsonEncoder.withIndent(' ').convert(option.toJson()));
final DateTime start = DateTime.now();
final Uint8List? result = await ImageEditor.editImage(
image: img,
imageEditorOption: option,
);
日志中的错误:
> Unhandled Exception:
> 'package:extended_image_library/src/extended_image_provider.dart':
> Failed assertion: line 34 pos 12: 'cacheRawData': you should set
> [ExtendedImageProvider.cacheRawData] to true, if you want to get
> rawImageData from provider.
如错误消息中所述,只需将 cacheRawData = true
添加到 ExtendedImageProvider
。