I am working on part of a Java application that takes an image as a byte array, reads it into a java.awt.image.BufferedImage instance and passes it to a third-p
If speed is an issue, and both BufferedImages are of the same bit-depth, arrangement, etc. (which seems like it must be true here) you can do this:
DataBuffer dbActual = myBufferedImage.getRaster().getDataBuffer();
DataBuffer dbExpected = bufferImageReadFromAFile.getRaster().getDataBuffer();
figure out which type it is, e.g. a DataBufferInt
DataBufferInt actualDBAsDBInt = (DataBufferInt) dbActual ;
DataBufferInt expectedDBAsDBInt = (DataBufferInt) dbExpected ;
do a few "sanity checks" for equals on the sizes and banks of the DataBuffers, then loop
for (int bank = 0; bank < actualDBAsDBInt.getNumBanks(); bank++) {
int[] actual = actualDBAsDBInt.getData(bank);
int[] expected = expectedDBAsDBInt.getData(bank);
// this line may vary depending on your test framework
assertTrue(Arrays.equals(actual, expected));
}
This is close to as fast as you can get cause you are grabbing a chunk of the data at a time, not one at a time.