Here you can find the source of decodeForRGBBufferedImage(String filePath)
Parameter | Description |
---|---|
filePath | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static BufferedImage decodeForRGBBufferedImage(String filePath) throws Exception
//package com.java2s; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import javax.imageio.ImageIO; public class Main { /**//w ww .j a v a 2s.com * Read the file and return it as RGB buffered image * @param filePath * @return image as buffered image * @throws Exception */ public static BufferedImage decodeForRGBBufferedImage(String filePath) throws Exception { BufferedImage bi = null; try { File file = new File(filePath); RenderedImage im = ImageIO.read(file); Dimension imageSize = new Dimension(im.getWidth(), im.getHeight()); bi = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB); drawImage(bi, im); } catch (Exception e) { System.out.println("cannot read file: " + filePath + " as RGB buffered image"); } return bi; } private static void drawImage(BufferedImage bi, RenderedImage im) { Graphics2D g = bi.createGraphics(); g.drawRenderedImage(im, new AffineTransform()); g.dispose(); } }