Pour mon projet, je dois lire chaque pixel d'une image, effectuer une opération mathématique sur chaque pixel, puis afficher les résultats du pixel modifié dans une image mise à jour. Pour cet exemple, j'ai pris la racine carrée de chaque pixel.comment utiliser setRGB() après avoir modifié les pixels? Dois-je utiliser hexadécimal?
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);
}
}
}}
Ma question est de savoir comment je peux définir et afficher les pixels modifiés dans le code setRGB()
. Lorsque j'insère un int - (int) v, l'image est entièrement noire. Dois-je changer l'int en un hexadécimal? J'ai essayé de faire quelque chose comme ceci: v=255*(Math.sqrt(rgb1[g])/Math.sqrt(255)); String vstring=Double.toHexString(v);
et ne me laisserais pas entrer une chaîne dans le setRGB(); = \