これが速いかどうかはわかりませんが、確かに便利です。私のソース データ配列は、 J4KSDKを使用して、Kinect のカラー ストリームから取得されました。
この方法での私の目標は、画像のバイナリ バイトを読み取ることでした。自分の用途に合わせて変更できると思います。
/* Reference imports */
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
/* method */
public byte[] getImage(byte[] bytes) throws IOException {
int width = 640;
int height = 480;
int[] shifted = new int[width * height];
// (byte) bgra to rgb (int)
for (int i = 0, j = 0; i < bytes.length; i = i + 4, j++) {
int b, g, r;
b = bytes[i] & 0xFF;
g = bytes[i + 1] & 0xFF;
r = bytes[i + 2] & 0xFF;
shifted[j] = (r << 16) | (g << 8) | b;
}
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bufferedImage.getRaster().setDataElements(0, 0, width, height, shifted);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "JPG", baos);
byte[] ret = baos.toByteArray();
return ret;
}