For my project, I have to read each pixel in an image, perform a math operation on each pixel, then display the results of the modified pixel in an updated image. For this example, I took the square root of each pixel.
public void rootCalc(){//go through the rows and columns for(int x=grayscale_orig.getWidth() - 1; x >= 1; x--)
{
for (int y = grayscale_orig.getHeight() - 1; y >= 0; y--)
{
//this is the pixel array
int[] rgb1 = getColors(grayscale_orig.getRGB(x, y));
for(int g=0; g<rgb1.length;g++)
{ //take the square root of each pixel value
v=255*(Math.sqrt(rgb1[g])/Math.sqrt(255));
//scale the squared value back into the 0-255 range and set the value
grayscale.setRGB(x,y,(int)v);
}
}
}}
My question is how I can set and display the modified pixels in the setRGB()
code. When I insert an int -- (int)v, the image is all black. Do I have to change the int to a hexadecimal? I tried doing something like this:
v=255*(Math.sqrt(rgb1[g]) / Math.sqrt(255));
String vstring=Double.toHexString(v);
and wouldn't let me input a string in the setRGB(); =\