【问题标题】:Flutter - Drawstring on captured photo from cameraFlutter - 从相机拍摄的照片上的拉绳
【发布时间】:2020-11-29 21:59:38
【问题描述】:

我正在使用这个https://github.com/brendan-duncan/image/wiki 尝试在我的图像上绘制文本我的问题是当我尝试传递的图像是图像时如何获取 Image.drawString() 中第一个参数所需的图像被相机插件捕捉到了吗?

final path = join(
  // Store the picture in the temp directory.
  // Find the temp directory using the `path_provider` plugin.
  (await getTemporaryDirectory()).path,
  '${DateTime.now()}.png',
);

// Attempt to take a picture and log where it's been saved.
await _controller.takePicture(path);
//this doesnt work
img.Image image = Image.file(File(path)) 
img.drawString(image, img.arial_24, 50, 50, "Hello World");

我收到此错误:

'Image(其中Image定义在 myflutterpath/packages/flutter/lib/src/widgets/image.dart)' 不能 分配给'Image类型的变量(其中Image定义在 /myflutterpath/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.1.4/lib/src/image.dart)'

【问题讨论】:

标签: flutter dart mobile


【解决方案1】:

您将 Flutter 中的 Image 小部件分配给 image 包中的 img.Image 变量。这些是完全独立的数据类型。

要做你想做的事,你需要创建一个img.Image 对象。由于您的图像源是 PNG 文件(根据文件扩展名猜测),您需要将其解码为原始像素数据。这可以通过您拥有的image 包中已包含的PngDecoder 来完成。

img.Image image = img.PngDecoder().decodeImage(await File(path).readAsBytes());

这会从您的 PNG 文件中创建一个 img.Image,而不是 Image 小部件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多