Infolinks In Text Ads

Adding Current Date and Time on Image in Java

 While scanning an Image you can placed current Date and Time on the image.

Some scanner don't have the functionality of Date And Time when scanning an image.
with the below code you can placed the Date and Time on image when scanning an image
Please see the below code.


package com.aurang.utk;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.imageio.ImageIO;

public class AddingDateOnImage {

      public static void main(String[] args) throws Exception {
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Calendar cal = Calendar.getInstance();
            System.out.println(dateFormat.format(cal.getTime()));
            String time = dateFormat.format(cal.getTime());
            String path = "C:/textimage.jpg";
            File file = new File(path);
            BufferedImage image = ImageIO.read(file);

            Graphics g = image.getGraphics();
            g.setFont(g.getFont().deriveFont(30f));

            g.drawString(time, 70, 1100);
            // g.dispose();

            ImageIO.write(image, "png", new File("test.png"));

      }

}

Output is:

Newer Post Older Post

Leave a Reply

Powered by Blogger.