BufferedImages.java Source code

Java tutorial

Introduction

Here is the source code for BufferedImages.java

Source

//package net.coobird.thumbnailator.util;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 * This class provides convenience methods for using {@link BufferedImage}s.
 * 
 * @author coobird
 *
 */
public final class BufferedImages {

    /**
     * Returns a {@link BufferedImage} with the specified image type, where the
     * graphical content is a copy of the specified image.
     * 
     * @param img      The image to copy.
     * @param imageType   The image type for the image to return.
     * @return         A copy of the specified image.
     */
    public static BufferedImage copy(BufferedImage img, int imageType) {
        int width = img.getWidth();
        int height = img.getHeight();

        BufferedImage newImage = new BufferedImage(width, height, imageType);
        Graphics g = newImage.createGraphics();

        g.drawImage(img, 0, 0, null);

        g.dispose();

        return newImage;
    }
}