Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display the greycale image in java after using setRGB?
    primarykey
    data
    text
    <p>M working on some image processing program and encountered a problem of displaying the greyscale image. What i did was, i extracted the pixel values using getRGB and then tried to change these pixel values. But after changing these pixel value i'm still getting the same image which was buffered before. My part of code is given below:-</p> <pre><code> int [] rgbArray=new int[width*height]; BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); buffer = ImageIO.read(new File(file)); //Before changing the pixel values buffer.getRGB(0, 0, width, height, rgbArray , 0,width ); int a = (0xff000000 &amp; rgbArray[0]) &gt;&gt;&gt; 24; int r = (0x00ff0000 &amp; rgbArray[0]) &gt;&gt; 16; int g = (0x0000ff00 &amp; rgbArray[0]) &gt;&gt; 8; int b = (0x000000ff &amp; rgbArray[0]); System.out.println("a " + a + " r " + r + " g " + g + " b " + b); System.out.println("rgbArray["+0+"] = "+ rgbArray[0]); for(int i = 0 ; i&lt;width*height; i++) { rgbArray[0]=0x808080; //Changing pixel values to grey } buffer.setRGB(0, 0, width, height, rgbArray , 0,width); //After changing the pixel values buffer.getRGB(0, 0, width, height, rgbArray , 0,width ); a = (0xff000000 &amp; rgbArray[0]) &gt;&gt;&gt; 24; r = (0x00ff0000 &amp; rgbArray[0]) &gt;&gt; 16; g = (0x0000ff00 &amp; rgbArray[0]) &gt;&gt; 8; b = (0x000000ff &amp; rgbArray[0]); System.out.println("a " + a + " r " + r + " g " + g + " b " + b); System.out.println("rgbArray["+0+"] = "+ rgbArray[0]); </code></pre> <p>Output for the pixel value is coming out to be correct for both original and new pixels but i'm not able to view the new image, it is showing the old i.e original image is shown not the changed image.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload