Convert Image File to Bufferedimage

Converting Image file to Buffered in Java

If you want to update the existing image file using java we need to convert the image file to bufferedimage object format. Here the below java code will convert the given input image file to BufferedImage object format. Just look at the below java program and use it.
change the image_file.gif to your file name.
//source code

import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.util.*;
import java.sql.*;
import java.awt.Graphics2D;

public class ImageFileToBufferedImage{
private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;
public static void main(String arg[]){
try{ File file = new File("image_file.gif");
Image image =;
BufferedImage cpimg=bufferImage(image,BufferedImage.TYPE_INT_RGB);
Graphics g = cpimg.createGraphics();
Font fnt=new Font("Impact",1,14);
Color fntC = new Color(0,100,0);
g.drawString("Text tobe displayed on the image",53,15);
File f1 = new File("img"+ ".gif");
ImageIO.write(cpimg, "gif", f1);
catch(Exception e){

public static BufferedImage bufferImage(Image image, int type) {
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, null, null);
return bufferedImage;

Related Topic Java Download Image from URL
Java - Write Text in Image file
A to Z Linux Commands quick reference sheet
PHP Code to Convert JPG Image to RGB Colored ASCII
How to Install CentOS by Bootable USB 2011   Privacy Policy  Terms of Service  Feedback