Here you can find the source of getImage(File imageFile)
public static BufferedImage getImage(File imageFile)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; import javax.swing.JOptionPane; public class Main { public static BufferedImage getImage(File imageFile) { BufferedImage al = null;/*from w w w .j a v a 2 s . c o m*/ try { String imageFileName = imageFile.getName(); String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1); Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat); ImageReader reader = readers.next(); if (reader == null) { JOptionPane.showConfirmDialog(null, "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net"); return null; } ImageInputStream iis = ImageIO.createImageInputStream(imageFile); reader.setInput(iis); al = reader.read(0); reader.dispose(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } catch (Exception e) { System.err.println(e.getMessage()); } return al; } }