Creating Image using Java Without any Extra Libs

Creating Image using Java Without any Extra Libs

Creating Image using Java Without any Extra Libs: Images are more interactive way to present the contents rather than presenting everything in plain texts. Dynamic content images can be created using java without any extra libs /additional libraries. Creating dynamic images can be automated using the below java program.



  • No Additional/Extra Libraries.
  • Need to give any background image as a input to this program. This program writes only the content over the image based on the x and y values mentioned.



What about the size of the image ?

As I explained above, image size will be same as the input image you passed to the program. This below java program is going to write just a content over the image whichever is defined.


Here for the example I have taken the image with 800*411 size one. If you are looking for any other size then take that size image and pass as a input to the below program.



Font, Font size can be customized ?

Yes. Below program provides the way to customize the font and font size as well.



Creating Image using Java Without any Extra Libs – Java Source Code:

Before running this program ensure you have changed the input and output paths and the image names respectively. For output image, name can be anything.

package in.javadomain;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class CreateImage {

public static void main(String[] args) {
Image img = new ImageIcon("C:\\Users\\Naveen\\Pictures\\empty-img.png")
BufferedImage bufferedImage = new BufferedImage(img.getWidth(null),
img.getHeight(null), BufferedImage.TYPE_INT_RGB);
// Define the textcolor
Color textColor = Color.yellow;
// Graphics g = bufferedImage.createGraphics();
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(img, 0, 0, null);
// Setting the font and font size, 30 is font size
Font myFont1 = new Font("Tahoma", 1, 30);
g.drawString("Creating image using java without any extra libs", 50,
// Setting the font and font size, 20 is font size
Font myFont2 = new Font("Arial", 1, 20);
g.drawString("", 630, 390);


try {
ImageIO.write(bufferedImage, "png", new File(
} catch (IOException e) {
// TODO Auto-generated catch block





Input Image:

Creating Image using Java Without any Extra Libs


Output Image:

Creating Image using Java Without any Extra Libs


1,155 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.