I want to store RGB values in a pixel array like so:
pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
where image
is:
BufferedImage image = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
I read the file using ImageIO
and it read fine, it's this part that's the problem. Here's the error:
Exception in thread "main" java.lang.ClassCastException: java.awt.image.DataBufferByte cannot be cast to java.awt.image.DataBufferInt
at SpritePractice.render(SpritePractice.java:114)
at SpritePractice.run(SpritePractice.java:75)
at SpritePractice.start(SpritePractice.java:124)
at SpritePractice.main(SpritePractice.java:132)
And pixels is an int array like so: int[] pixels
What do I do? As a side question, can somebody explain casting and what it does? thanks!
EDIT:
Printed out image.getRaster().getDataBuffer()
on console
Heres output:
java.awt.image.DataBufferByte@716925b0
Clearly there's something wrong here. I specified that BufferedImage image = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
and it's reading DataBufferByte
...