Java AWT BufferedImage copy or create Image

Description

Java AWT BufferedImage copy or create Image



//package com.demo2s;

import java.awt.image.BufferedImage;

public class Main {

    public static BufferedImage copyOrReallocImage(BufferedImage cache, BufferedImage source) {
        int height = source.getHeight();
        int width = source.getWidth();
        if (cache == null || cache.getWidth() != width || cache.getHeight() != height
                || cache.getType() != source.getType()) {
            cache = new BufferedImage(width, height, source.getType());
        }/*from ww w  .ja v  a2 s.c om*/
        cache.getRaster().setRect(source.getRaster());
        return cache;
    }
}



PreviousNext

Related