简体   繁体   中英

In java, the pixel values with which I draw an image and the values extract from the image after drawing it is not remaining same

I have used the following code to extract pixel values of an image.

    int[][] pixels = new int[w][h];

    for( int i = 0; i < w; i++ )
        for( int j = 0; j < h; j++ )
            pixels[i][j] = imgBuffer.getRGB( i, j );

Now I modified the pixel values and drew the new figure by

    BufferedImage image=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
    for( int i = 0; i < w; i++ )
        for( int j = 0; j < h; j++ )
            image.setRGB( i, j,pixels[i][j] );

Now when i try to get the values by

    int[][] pixels1 = new int[w1][h1];

    for( int i = 0; i < w1; i++ )
        for( int j = 0; j < h1; j++ )
            pixels1[i][j] = imgBuffer1.getRGB( i, j );

This is giving me completely new values

You're not showing where imgBuffer and imgBuffer1 come from. Are they the same object, or are they two different objects referring to the same buffer in memory, or are they two different objects referromg to entirely different buffers? If they don't point to the same buffer in memory then it stands to reason that they at least could, and probably would, produce different outputs.

Also, have you tried doing simple tests, like using a solid color buffer (say, solid blue) for the input and extracting the pixel data multiple times to see if it's different from the input? Also, if it's different, is it at least consistently different (the same shift happens between one color and the next, the same color always comes out the second time regardless of the input, etc.)?

Part of what your question is currently lacking is the process by which you've tried to determine why this is happening - what have you already tried in order to figure out what's happening, and what were the results?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM