static byte[] imagePixelsToRGBAWithSize(BufferedImage etc img) { if (img == null) null; int w = img.getWidth(), h = img.getHeight(), n = w*h; byte[] out = new[(n+2)*4]; // store width and height intToBytes_inArray_littleEndian(w, out, 0); intToBytes_inArray_littleEndian(h, out, 4); // store pixels copyIntArrayToByteArray_littleEndian(pixelsOfBufferedImage(img), out, 8); ret out; }