Here you can find the source of declareNewBufferedImageAndCopy(BufferedImage img)
public static BufferedImage declareNewBufferedImageAndCopy(BufferedImage img)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import javax.imageio.ImageTypeSpecifier; public class Main { public static BufferedImage declareNewBufferedImageAndCopy(BufferedImage img) { BufferedImage imgOut = declareNewBufferedImage(img); copyBufferedImage(img, imgOut);/*ww w .jav a 2 s.com*/ return imgOut; } public static BufferedImage declareNewBufferedImage(int x, int y) { //naredi novo prazno sliko zeljene velikosti BufferedImage imgOut = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB); return imgOut; } public static BufferedImage declareNewBufferedImage(BufferedImage img) { //naredi novo prazno sliko enake velikosti //kot jo ima tista, ki jo podamo kot argument ImageTypeSpecifier its = new ImageTypeSpecifier(img); BufferedImage imgOut = new BufferedImage(img.getWidth(), img.getHeight(), its.getBufferedImageType()); return imgOut; } public static BufferedImage declareNewBufferedImage(BufferedImage img1, BufferedImage img2) { int h1 = img1.getHeight(); int w1 = img1.getWidth(); int h2 = img2.getHeight(); int w2 = img2.getWidth(); int height = (h1 < h2) ? h1 : h2; int width = (w1 < w2) ? w1 : w2; //uzame sirino od ozje slike in visino od nizje //taksnih dimenzij je potem izhodna slika ImageTypeSpecifier its = new ImageTypeSpecifier(img1); BufferedImage imgOut = new BufferedImage(width, height, its.getBufferedImageType()); return imgOut; } public static void copyBufferedImage(BufferedImage imgOrig, BufferedImage imgCopy) { int height = imgCopy.getHeight(); int width = imgCopy.getWidth(); int rgb; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { rgb = imgOrig.getRGB(j, i); imgCopy.setRGB(j, i, rgb); } } } }