Java BufferedImage Create getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height)

Here you can find the source of getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height)

Description

Converts an integer array with Red, Green and Blue values of each pixel, sequentially, to a BufferedImage

License

Open Source License

Parameter

Parameter Description
rgb a parameter
width a parameter
height a parameter

Return

correspondent buffered image

Declaration

public static BufferedImage getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height) 

Method Source Code


//package com.java2s;
/*/*ww  w  .j av a2s.  co  m*/
 * The MIT License (MIT)
 * Copyright (c) 2014 Daniel Costa Gimenes
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 * software and associated documentation files (the "Software"), to deal in the Software 
 * without restriction, including without limitation the rights to use, copy, modify, 
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to the following 
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Converts an integer array with Red, Green and Blue values of each pixel,
     * sequentially, to a BufferedImage
     * 
     * @param rgb
     * @param width
     * @param height
     * @return correspondent buffered image
     */
    public static BufferedImage getBufferedImageFrom3bytePixelArray(int[] rgb, int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        image.setRGB(0, 0, width, height, rgb, 0, width);
        for (int i = 0; i < image.getWidth(); i++) {
            for (int j = 0; j < image.getHeight(); j++) {
                int[] c;
                c = image.getRaster().getPixel(i, j, new int[4]);
                if (c[0] != c[1] || c[0] != c[2] || c[1] != c[2]) {
                    System.out.println(c[0] + " " + c[1] + " " + c[2]);
                    System.out.println(rgb[i + (i * j)]);
                }
            }
        }
        return image;
    }
}

Related

  1. getBufferedImage(String imageFile, Component c)
  2. getBufferedImage(String imagePath)
  3. getBufferedImageAsType(int type, BufferedImage image, int sizeX, int sizeY)
  4. getBufferedImageBytes(BufferedImage bufferedImage)
  5. getBufferedImaged(Image img, int width, int height)
  6. getBufferedImageFromFile(String fileName)
  7. getBufferedImageFromPath(String path)
  8. getBufferedImageMixedImages(BufferedImage image1, BufferedImage image2, int xImage2, int yImage2)
  9. getBufferedImageType(String encodeType)