Java BufferedImage Operation intBuffer2BufferedImage(IntBuffer ib, BufferedImage img)

Here you can find the source of intBuffer2BufferedImage(IntBuffer ib, BufferedImage img)

Description

Convert IntBuffer to BufferedImage.

License

Open Source License

Parameter

Parameter Description
ib each 4-byte (ARGB) integer in IntBuffer corresponds to a pixel in the BufferedImage ib should have width*height of integers. ib is little endian so the byte order is BGRA. ib is a direct buffer which has no backup array, so ib.array() will fail.
bi BufferedImage should have type TYPE_INT_ARGB

Declaration

public static void intBuffer2BufferedImage(IntBuffer ib, BufferedImage img) 

Method Source Code

//package com.java2s;
/*/* w ww  .j a  va  2 s .c  o m*/
 * Image conversion utilities.
 * 
 * Copyright (c) 2006 Jean-Sebastien Senecal (js@drone.ws)
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
 * Ave, Cambridge, MA 02139, USA.
 */

import java.awt.image.BufferedImage;

import java.nio.IntBuffer;

public class Main {
    /**
     * Convert IntBuffer to BufferedImage. The size of IntBuffer should equal to
     * the size of BufferedImage, i.e. ib.capacity() == img.getWidth() *
     * img.getHeight()
     * 
     * @author Ying Yin
     * 
     * @param ib each 4-byte (ARGB) integer in IntBuffer corresponds to a pixel in
     *          the BufferedImage ib should have width*height of integers. ib is
     *          little endian so the byte order is BGRA. ib is a direct buffer
     *          which has no backup array, so ib.array() will fail.
     * @param bi BufferedImage should have type TYPE_INT_ARGB
     */
    public static void intBuffer2BufferedImage(IntBuffer ib, BufferedImage img) {
        int[] rgbArray = new int[ib.capacity()];
        ib.rewind();
        ib.get(rgbArray);
        img.setRGB(0, 0, img.getWidth(), img.getHeight(), rgbArray, 0, img.getWidth());
    }
}

Related

  1. highlight(BufferedImage img, Color source, Color dest)
  2. hitTest(BufferedImage image, int x, int y)
  3. hueShift(BufferedImage image, int hue)
  4. inColormap(float[][] in, float min, float max, float[][] colormap, BufferedImage b)
  5. indexToDirectColorModel(BufferedImage image)
  6. intensityArrayToBufferedImage(byte[] array, int w, int h)
  7. interp(BufferedImage img1, BufferedImage img2, int weight1, int weight2)
  8. knit(BufferedImage[] buffImages)
  9. layer(BufferedImage source, BufferedImage destination, int x, int y)