Here you can find the source of getByteBuffer(BufferedImage bufferedImage)
public static ByteBuffer getByteBuffer(BufferedImage bufferedImage)
//package com.java2s; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image.Raster; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { public static ByteBuffer getByteBuffer(BufferedImage bufferedImage) { Raster raster = bufferedImage.getRaster(); DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer(); byte[] data = dataBufferByte.getData(); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length); byteBuffer.order(ByteOrder.nativeOrder()); byteBuffer.put(data, 0, data.length); byteBuffer.flip();//from w ww . j ava 2s. co m return byteBuffer; } }