【问题标题】:Capture a photo, save temporarily, and open as bitmap拍摄照片、临时保存并以位图形式打开
【发布时间】:2019-12-24 22:55:24
【问题描述】:

我是 Flutter 的新手。

我需要什么:

从 android temp 文件夹中打开一张照片并转换为位图。

我在做什么:

跟随本教程:https://flutter.dev/docs/cookbook/plugins/picture-using-camera

  1. 我正在调用“CameraController”中的“takePicture”方法 将照片保存在临时文件中;
  2. 我打开文件并尝试转换为位图:

代码:

final Image photo = Image.file(File(imagePath));  
final AssetImage image = photo.image;  
final Bitmap bitmap = Bitmap.fromAssetImage(image); 

会发生什么:

本地> /data/data/io.flutter.plugins.firebasemlvisionexample/cache/2019-08-19 14:14:58.720970.png.
I/flutter (7943): 'FileImage' 类型不是'AssetImage' 类型的子类型

如果使用“Bitmap.fromImage(photo)”,VScode 会显示:

参数类型'Image(其中Image定义在. /Users/luis/development/flutter/packages/flutter/lib/src/widgets/image.dart)' 不能分配给参数类型“图像”(其中定义了图像 在 /Users/luis/development/flutter/bin/cache/pkg/sky_engine/lib/ui/painting.dart)'。

【问题讨论】:

    标签: flutter android-bitmap


    【解决方案1】:

    这样做:

    Image.asset('images/cat.png')
    

    Images.asset

    【讨论】:

    • 我将图像保存在临时文件夹中,要以这种方式工作,我必须保存在“资产”文件夹中,然后手动删除文件?
    • 你用的是什么包的位图?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    相关资源
    最近更新 更多