I have a situation where I want to update the pixel buffer (int) for my BufferedImage.
I get the int array with the pixel info like this:
img = gc.createCompatibleImage(w, h, transparency);
imgData = (DataBufferInt)img.getRaster().getDataBuffer();
pixBuffer = imgData.getData();
Now I can alter the contents of the pixBuffer, however if I want to recreate the pixBuffer with a new int the reference to this new pixBuffer is lost by the BufferedImage, whats the best way of recreating this reference? I currently do it like this, but im not sure its the best way:
DataBufferInt buffer = new DataBufferInt(pixBuffer, pixBuffer.length);
SampleModel sm = cm.createCompatibleSampleModel(width, height);
WritableRaster raster = Raster.createWritableRaster(sm, buffer, null);
I also tried:
WritableRaster raster = img.getRaster();
But that doesnt seem to work?