Here you can find the source of setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels)
public static void setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels)
//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); } }