Results 1 to 7 of 7
  1. #1
    SreerajSarma is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default problem with pixel values of an image

    i am writing a code to encrypt/decrypt image files.
    first i am reading pixel values from the source image
    then converting it into alpha array,red array,green array,blue array
    then after manipulating the arrays
    i am writing the pixel values to get encrypted image
    //i am printing the pixel values which i am writing to file
    all is well till here(image gets encrypted)
    but when i am reading the encrypted image again(for decryption)
    the pixel values are different from what i have stored during encryption
    as i am not able to read the original pixel values which were stored during encryption phase
    i am not able to decrypt the image correctly

    part of the code i am is attached

    please help
    Attached Files Attached Files

  2. #2
    SreerajSarma is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    no replies??

    still facing the same problem....

  3. #3
    SreerajSarma is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    do i need to move it to java 2d forum..

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    The problem you are having, is that screen coordiantes and array indexes don't work the same way, if you have a table like this:
    Java Code:
    0,0,0,0
    0,0,1,0
    0,0,0,0
    the position of the 1 would be expressed as following:
    array index = table[1][2]
    that is, 2nd row, 3rd collumn
    on screen coordinates: 2,1

    The gist of this is, in arrays, the first number represents which array to search in a 2d table (top to bottom), while the first number of on screen coordinates describes the amount of right shift (x coordinate). So, if you store image info in an array, be prepared for the fact that the array will need to be mirrored along the diagonal.

  5. #5
    SreerajSarma is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    thanks for replying

    i changed the code replaced i,j loops for getting the mirror values about diagonal

    but still i am getting diiferent values for pixel when i read the file later.

    Java Code:
         int pixel;
       BufferedImage img=new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB);
    
    
      // inter changed  the i ,j loop
          for ( j = 0; j < 320; j++) 
       {
            for ( i = 0; i < 240; i++)
       {
            System.out.println("x,y: " + j + ", " + i);
           
          pixel = (alphArray[j][i]<<24)|(redarray[j][i]<<16)|(greenarray[j][i]<<8)|bluearray[j][i];
        
         //used 2d array for manipulation
        
        int alpha = (pixel >> 24) & 0xff;
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        
        System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
        
        //printing pixel values to check which values are bieng stored in file 
    
        img.setRGB(j,i,pixel1);
        }
        }
    
    
    	File f = new File("encrypt.jpg");
         		try {
            		         ImageIO.write(img, "jpg", f);
      				
                        }
                             catch (IOException ex)
                            {
           			     ex.printStackTrace();
            		}
    code used for reading encrypted file
    Java Code:
    BufferedImage image = ImageIO.read(this.getClass().getResource("encrypt.jpg"));
    //reading file in decryption phase
        int w = image.getWidth();
        int h = image.getHeight();
       
    
        for (int i = 0; i < h; i++) {
          for (int j = 0; j < w; j++) {
            System.out.println("x,y: " + j + ", " + i);
            int pixel = image.getRGB(j, i);
            int alpha = (pixel >> 24) & 0xff;
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        
        System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
    
    //printed values are different from what i have stored during encryption phase

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Isn't the jpeg format a (lossy) compressed format of an image? If I'm correct that implies that the information is not written as you think it is and (of course) won't be read back indentical as how you thought you wrote it before. Try the .png format instead.

    kind regards,

    Jos

  7. #7
    SreerajSarma is offline Member
    Join Date
    Mar 2010
    Posts
    6
    Rep Power
    0

    Default

    does png images also have the argb format??
    can the pixel values be converted into alpha, red ,green, blue array in png images??

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 05:01 PM
  2. Identify pixel in the image.
    By Maiquelnet in forum Java 2D
    Replies: 2
    Last Post: 11-12-2009, 08:55 PM
  3. Replies: 14
    Last Post: 04-10-2009, 09:46 AM
  4. how to get rgb value each pixel of an image file
    By tOpach in forum New To Java
    Replies: 1
    Last Post: 03-28-2009, 05:38 PM
  5. Replies: 1
    Last Post: 07-17-2007, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •