Returns a new BufferedImage using the same color model as the image passed as a parameter. - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

Returns a new BufferedImage using the same color model as the image passed as a parameter.

Demo Code

/*//w w  w  . java2 s .  c o m
 * @(#)EffectUtils.java   1.2 07/12/12
 *
 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
//package com.java2s;

import java.awt.image.BufferedImage;

import java.awt.image.ColorModel;

public class Main {
    /**
     * <p>
     * Returns a new <code>BufferedImage</code> using the same color model as
     * the image passed as a parameter. The returned image is only compatible
     * with the image passed as a parameter. This does not mean the returned
     * image is compatible with the hardware.
     * </p>
     * 
     * @param image
     *            the reference image from which the color model of the new
     *            image is obtained
     * @return a new <code>BufferedImage</code>, compatible with the color model
     *         of <code>image</code>
     */
    public static BufferedImage createColorModelCompatibleImage(
            BufferedImage image) {
        ColorModel cm = image.getColorModel();
        return new BufferedImage(cm, cm.createCompatibleWritableRaster(
                image.getWidth(), image.getHeight()),
                cm.isAlphaPremultiplied(), null);
    }
}

Related Tutorials