Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw String into Image?

Tags:

flutter

dart

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..

like image 570
edodije Avatar asked Dec 18 '25 21:12

edodije


1 Answers

You can draw string into image using image 2.1.12

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;
  }
like image 67
Darshan Prajapati Avatar answered Dec 22 '25 00:12

Darshan Prajapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!