I have an array of integers which represent a RGB image and would like to convert it to a byte array and save it to a file.
What\'s the best way to convert an array
if your intent is to save to file you maybe want to save directly in a file using FileOutputStream.write:
OutputStream os = new FileOutputStream("aa");
int[] rgb = { 0xff, 0xff, 0xff };
for (int c : rgb) {
os.write(c);
}
os.close();
since it:
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.