Java BufferedImage Operation setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels)

Here you can find the source of setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels)

Description

set Image Int Pixels

License

Open Source License

Declaration

public static void setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead,
            IntBuffer pixels) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 joey.enfield.//from  w w  w.j av a 2s .co m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     joey.enfield - initial API and implementation
 ******************************************************************************/

import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;

import java.awt.image.WritableRaster;
import java.nio.IntBuffer;

public class Main {
    public static void setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead,
            IntBuffer pixels) {
        setImageIntPixels(image, 0, 0, image.getWidth(null), image.getHeight(null), allowDeoptimizingDirectRead,
                pixels);
    }

    public static void setImageIntPixels(BufferedImage bim, int x, int y, int width, int height,
            boolean allowDeoptimizingDirectRead, IntBuffer pixels) {
        WritableRaster raster = bim.getRaster();
        if (allowDeoptimizingDirectRead && raster.getParent() == null
                && raster.getDataBuffer().getNumBanks() == 1) {
            DataBuffer b = bim.getRaster().getDataBuffer();
            if (b instanceof DataBufferInt) {
                IntBuffer.wrap(((DataBufferInt) b).getData()).put(pixels);
                return;
            }
        }

        IntBuffer b = IntBuffer.allocate(width * height);
        b.put(pixels);
        b.rewind();
        int[] array = b.array();
        bim.setRGB(x, y, width, height, array, 0, width);
    }
}

Related

  1. setBackgroud(BufferedImage image, Color backgroundColor)
  2. setBGRPixels(byte[] bgrPixels, BufferedImage img, int x, int y, int w, int h)
  3. setBrightnessFactor(BufferedImage img, float multiple, BufferedImage dest)
  4. setColor(BufferedImage image, int x, int y, int[] color, String colorModel)
  5. setCompressionType(ImageWriteParam param, BufferedImage image)
  6. setLockImage(BufferedImage image)
  7. setLuminance(BufferedImage image, int x, int y, float value)
  8. setPixel(BufferedImage img, int x, int y, int c)
  9. setPoint(BufferedImage image, int x, int y, int factor, Color color)