Awesome Speeds With VolatileImage

Word of advice to anyone wanting to meddle with the internal buffer on a BufferedImage:


//This works (for <type> being int, byte or short, and <Type> being Int, Byte or Ushort)
<type>[] bufferData = ((java.awt.image.DataBuffer<Type>)BufferedImage.getRaster().getDataBuffer()).getData();

//This, on the other hand, does not (The BufferImage.getData() method creates a copy of the buffer, that is not backed up by the actual image.
<type>[] bufferData = ((java.awt.image.DataBuffer<Type>)BufferedImage.getData().getDataBuffer()).getData();


Yes, I spent all day today wondering why my filters where not working. :clue:

Edit: Corrected typo on data buffer types. It’s java.awt.image.DataBufferUshort, not DataBufferShort

Perhaps you already knew, but directly accessing the raster of a BufferedImage tends to make it so the image cannot be accelerated anymore.

Wow! Did you read any of the last page? You might find why that point is irrelevant! :stuck_out_tongue: