2016-08-31 8 views
0

私のプロジェクトでは、イメージの各ピクセル値を取得した後、ピクセルの復号化を行い、ピクセルに新しい値を設定します。しかし、変更されたピクセル値を持つ新しいイメージを作成した後、新しいイメージは、そのまま私が変更したものと同じピクセル値を含むことはできません。主なピクセル値は変化します。この問題を解決する方法。 私のコードはイメージを描画した後にピクセルが変更される

 for(i=0;i<width;i++){ 
     for(int j=0;j<height;j++){ 

      //int p1 = pix[i][j]; 
      int a1 = ealph[i][j];   
      int r3 = ered[i][j]; 
      int g1 = ered[i][j]; 
      int b1 = ered[i][j]; 


      int p1 = (a1<<24) | (r3<<16) | (g1<<8) | b1; 
       img.setRGB(i, j, p1); 

     } 

    } 

    try{ 
     f = new File("C:\\Users\\chukkapalli\\workspace\\Des_Encryption\\decripted_img.jpg"); 
     ImageIO.write(img, "jpg", f); 
     }catch(IOException e){ 
     System.out.println(e); 
     } 


    f = null; 

img = null; 
    try{ 
      f = new File("C:\\Users\\chukkapalli\\workspace\\Des_Encryption\\decripted_img.jpg"); 
      img = ImageIO.read(f); 
     }catch(IOException e){ 
      System.out.println(e); 
     } 
    width = img.getWidth(); 
    height = img.getHeight(); 

    for(i=0;i<width;i++){ 
      for(int j=0;j<height;j++){ 

       int p1 = img.getRGB(i,j); 
       e1alph[i][j] = (p1>>24)&0xff; 
       e1red[i][j] = (p1>>16)&0xff; 
       egreen[i][j] = (p1>>8)&0xff; 
       eblue[i][j] = p1&0xff; 

       System.out.println("orginal image- "+ealph[i][j]+" "+ered[i][j]+" "+ered[i][j]+" "+ered[i][j]+" created -- "+e1alph[i][j]+" "+e1red[i][j]+" "+egreen[i][j]+" "+eblue[i][j]); 

      } 

     } 

出力はどのように私は後に作成されて変化画素値との画像を作成することができます

 orginal image- 0 33 33 33 created -- 255 35 35 35 
    orginal image- 0 38 38 38 created -- 255 41 41 41 
    orginal image- 0 140 140 140 created -- 255 142 142 142 
    orginal image- 0 81 81 81 created -- 255 51 51 51 
    orginal image- 0 22 22 22 created -- 255 21 21 21 
    orginal image- 0 127 127 127 created -- 255 135 135 135 
    orginal image- 0 126 126 126 created -- 255 127 127 127 
    orginal image- 0 63 63 63 created -- 255 62 62 62 
    orginal image- 0 244 244 244 created -- 255 250 250 250 
    orginal image- 0 11 11 11 created -- 255 0 0 0 
    orginal image- 0 13 13 13 created -- 255 11 11 11 
    orginal image- 0 171 171 171 created -- 255 175 175 175 
    orginal image- 0 126 126 126 created -- 255 130 130 130 
    orginal image- 0 8 8 8 created -- 255 0 0 0 
    orginal image- 0 6 6 6 created -- 255 14 14 14 
    orginal image- 0 248 248 248 created -- 255 244 244 244 
    orginal image- 0 109 109 109 created -- 255 128 128 128 
    orginal image- 0 107 107 107 created -- 255 86 86 86 
    orginal image- 0 50 50 50 created -- 255 48 48 48 
    orginal image- 0 104 104 104 created -- 255 131 131 131 
    orginal image- 0 110 110 110 created -- 255 95 95 95 
    orginal image- 0 127 127 127 created -- 255 128 128 128 

です。 ありがとうございます。

答えて

1

PNGのようなロスレスフォーマットをお試しください。 JPGはその圧縮のピクセル値を変更し、作成したのとまったく同じように読み取ることはできません。

+0

ありがとうございました。その完全に動作します。 –

関連する問題