get Buffered Image As Type - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

get Buffered Image As Type

Demo Code


//package com.java2s;

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 {/* w  w  w. ja  va2  s.  c om*/
            // '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;
        }
    }
}

Related Tutorials