Here you can find the source of loadImage(final File refDirectory, final String imageFileName)
public static BufferedImage loadImage(final File refDirectory, final String imageFileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Main { private static final boolean USE_GRAPHICS_ACCELERATION = false; private final static GraphicsConfiguration gc = (USE_GRAPHICS_ACCELERATION) ? GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration() : null;/* w w w. jav a 2 s . c o m*/ public static BufferedImage loadImage(final File refDirectory, final String imageFileName) throws IOException { final File imageFile = new File(refDirectory, imageFileName); if (!imageFile.canRead()) { return null; } final BufferedImage image = ImageIO.read(imageFile); // convert image to compatible image: return copyImage(image, newImage(image.getWidth(), image.getHeight())); } public static BufferedImage copyImage(final BufferedImage srcImage) { return copyImage(srcImage, newImage(srcImage.getWidth(), srcImage.getHeight())); } public static BufferedImage copyImage(final BufferedImage srcImage, final BufferedImage destImage) { // Copy image to the output buffered image final Graphics2D g = destImage.createGraphics(); try { g.drawImage(srcImage, 0, 0, null); } finally { g.dispose(); } return destImage; } public static BufferedImage newImage(final int w, final int h) { if (USE_GRAPHICS_ACCELERATION) { return gc.createCompatibleImage(w, h); } return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); } }