Here you can find the source of getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)
private static BufferedImage getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.image.BufferedImage; public class Main { private static BufferedImage getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY) { if (image.getType() == type) { return image; } else {/*from w ww. j av a 2 s . c o m*/ // 'type' should be one of BufferedImage.TYPE_* BufferedImage result = new BufferedImage(sizeX, sizeY, type); Graphics g = result.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return result; } } }