Another way to work with various graphic formats is the ImageIO class. The following example converts jpg to png and draws a cross.
public class ImageReaderExample {
public static void main(String[] args) {
try{
BufferedImage image = ImageIO.read(new File("/tmp/input.jpg"));
image.getGraphics().drawLine(1, 1, image.getWidth()-1, image.getHeight()-1);
image.getGraphics().drawLine(1, image.getHeight()-1, image.getWidth()-1, 1);
ImageIO.write(image, "png", new File("/tmp/output.png"));
}
catch (IOException e){
e.printStackTrace();
}
}
}
source
share