Java BufferedImage setRGB, getRGB error -


I am editing a buffard image.

After changing the pixel in the picture, I make a check to ensure that the new value is that I expect it, however, they have not changed in the specified pixel color !

I thought it might be something with alpha values, so I recently added a step which removes the alpha value from the original pixel, and ensures that the new color is inserted back into the image. For that value is used.

  System.out.println (newColors [0] + "," + newColors [1] + "," + new collar [2]); Color old color = new color (image.getRGB (x, y)); Color new color = new color (new color [0], new color [1], new color [2], old collar. Gatealfa ()); // Create a new color with RGB values; Image.setRGB (x, y, newColor.getRGB ()); // Set RGB of pixels in the image. For (int cola: gate rgb (x, y)) {System.out.println (col);  

method getRGBs () returns an array where

  • index is 0 red value
  • Index 1 is green
  • The index is blue 2.

Output looks:

  206, 207, 207 204 203 203  

As you can see , The values ​​come back from the 206, 207, 207 image such as 204, 203, 203 - In fact, I get every pixel in 204, 203, 203 What am I doing wrong? It just does not understand thanks in advance!

I got my answer online, I will briefly summarize it:

< P> In a blazed image with a color model, the closest color to the pixel is chosen. This means that you can not get the color you want, because the colors you can set, are limited to colors only color colors. You can create your own buffalo image and drag the source image onto it and then manipulate those pixels.
  BufferedImage Basic = imageIO.read (new file (file.getPath) ())); Image = new buffard image (original .getWidth (), original GetHeight (), buffed image. TYPE_3BYTE_BGR); Image.getGraphics () DrawImage (root, 0, 0, empty); (Int y = 0; y & lt; original.getHeight (); y ++) {for (int x = 0; x & lt; original ;getWidth (); x ++) {image.setRGB ( X, y, original.getRGB (x, y)); }}  

Resolved that problem, clearly, I did not specify the specified colors in ColorModel and thus it could adjust the pixels in the closest color .


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -