如何将字符串绘制成图像? [英] How to draw String into Image?

查看:103
本文介绍了如何将字符串绘制成图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用image_picker库从Camera获取图片,然后我想将照片拍摄日期和时间的信息添加到图像中。
那可能..?谢谢。

I'm trying to get picture from Camera using image_picker library, then I want to add information of the date and time the picture was taken into the image..? Is that possible..? Thank you..

推荐答案

您可以使用图片2.1.12

您必须在dart文件中的库下面导入

You have to import below library in your dart file

import 'package:image/image.dart' as img;

捕获图像并在图像上绘制字符串的功能

Function for capture image and draw string on image

  Future<File> drawTextOnImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);

    var decodeImg = img.decodeImage(image.readAsBytesSync());

    img.drawString(decodeImg, img.arial_48, 0, 0, DateTime.now().toString());

    var encodeImage = img.encodeJpg(decodeImg, quality: 100);

    var finalImage = File(image.path)..writeAsBytesSync(encodeImage);

    return finalImage;
  }

这篇关于如何将字符串绘制成图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆