Re: BufferedImage's raster
Quote:
Originally Posted by
PhQ
I was wondering how does the imgg in createImage() method change without me changing anything in the imgg?
I just fill the pixels array with random numbers and the imgg changes without me actauly doing anything to the imgg.
It would make sense if I would have to do imgg.getRaster().getDataBuffer().setData(pixels);
I have a feeling that it has something to do with the raster.
Let's look at what you're doing:
Code:
// create an empty BufferedImage and have imgg refer to it.
BufferedImage imgg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// extract the data model of the image. This is "live" data -- you change the values held by this array,
// you will change the image itself.
int[] pixels = ((DataBufferInt)imgg.getRaster().getDataBuffer()).getData();
// and that's exactly what you do -- change the values held by the array.
for(int i = 0; i < pixels.length;i++){
pixels[i] = rand.nextInt();
}
As per the comments, you're changing the raw ints that define the image, not a copy of the data model, but the actual model itself. It should come as no surprise that you'll see your "noise" image when you make these changes.
Re: BufferedImage's raster
Quote:
Originally Posted by
Fubarable
Let's look at what you're doing:
Code:
// create an empty BufferedImage and have imgg refer to it.
BufferedImage imgg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// extract the data model of the image. This is "live" data -- you change the values held by this array,
// you will change the image itself.
int[] pixels = ((DataBufferInt)imgg.getRaster().getDataBuffer()).getData();
// and that's exactly what you do -- change the values held by the array.
for(int i = 0; i < pixels.length;i++){
pixels[i] = rand.nextInt();
}
As per the comments, you're changing the raw ints that define the image, not a copy of the data model, but the actual model itself. It should come as no surprise that you'll see your "noise" image when you make these changes.
Makes sense. Thank you :)
Re: BufferedImage's raster