I have this code:
public Image toNegative()
{
int imageWidth = originalImage.getWidth();
int imageHeight = originalImage.getHeight();
int [] rgb = n
There are two problems:
The width of the array is not the width of the image but the "scan size" (some image sizes get padded with extra pixels)
If you call getRGB()
with a null
array, the method will create an array but it won't change the rgb
reference - Java doesn't support "out parameters".
To make this work, use
rgb = originalImage.getRGB(0, 0, imageWidth, imageHeight, null, 0,imageWidth);