Java BufferedImage Operation declareNewBufferedImageAndCopy(BufferedImage img)

Here you can find the source of declareNewBufferedImageAndCopy(BufferedImage img)

Description

declare New Buffered Image And Copy

License

Open Source License

Declaration

public static BufferedImage declareNewBufferedImageAndCopy(BufferedImage img) 

Method Source Code

//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);
            }
        }
    }
}

Related

  1. criarImagemCompativel(BufferedImage original, int largura, int altura, boolean manterQualidade)
  2. cutToSquare(BufferedImage src)
  3. cylindricalMapping(BufferedImage img, double f)
  4. darkenImage(final BufferedImage image, final float darken)
  5. declareNewBufferedImage(int x, int y)
  6. depalettize(BufferedImage img, int maxBytes)
  7. determineBackgroundColor(BufferedImage bim)
  8. doInGraphics(final BufferedImage image, final Consumer consumer)
  9. duplicate(BufferedImage image)