0

我正在使用以下代码设置具有新值的图像数组的初始 8*8 像素位置,但不幸的是它返回了初始值。示例我将图像数组的初始 8*8 值更改为 16 并构建图像。当我检索该图像并读取前 8*8 值时。我已经看到这些值与图像数组先前的值相同。(在将值设置为 8*8 数组之前)这意味着 16 未分配给图像数组 8*8堵塞

请建议我必须在我的代码中进行的更改

  /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author pratibha
 */
public class ConstructImage{
    int[][] PixelArray;
    public ConstructImage(){
        try{

      BufferedImage bufferimage=ImageIO.read(new File("C:\\image_1.jpg"));
       int height=bufferimage.getHeight();
       int width=bufferimage.getWidth();
       PixelArray=new int[width][height];
       for(int i=0;i<width;i++){
            for(int j=0;j<height;j++){
                PixelArray[i][j]=bufferimage.getRGB(i, j);
            }
        }

        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++){
           //   System.out.print(PixelArray[i][j]+" , ");
                PixelArray[i][j]=16;
            }
            System.out.println("");
        }

        int[][] NewPixel=PixelArray; 




      BufferedImage bufferImage2=new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
          for(int x=0;x<width;x++){
                for(int y=0;y<height;y++){
          bufferImage2.setRGB(x, y,NewPixel[x][y]);
          Color c=new Color(NewPixel[x][y]);
          System.out.println(" , "+NewPixel[x][y]+" , "+c.getRGB());

            }
                System.out.println();
         }

         File outputfile = new File("C:\\img.jpg");
         ImageIO.write(bufferImage2,"jpg", outputfile);



////        ///////////////////////////////////////////////////////////////////
   BufferedImage bufferimage1=ImageIO.read(new File("C:\\img.jpg"));
        int height1=0;
        height1=bufferimage1.getHeight();
        int width1=0;
        width1=bufferimage1.getWidth();
        int[][] PixelArray1=new int[width1][height1];
        for(int i=0;i<width1;i++){
            for(int j=0;j<height1;j++){
                PixelArray1[i][j]=bufferimage1.getRGB(i, j);
            }
        }
        ///////create Image from this PixelArray
        int[][] RetrivePixel=PixelArray1;
         for(int i=0;i<1;i++){
            for(int j=0;j<8;j++){
               //olor c=new Color(PixelArray1[i][j]);
                int var=RetrivePixel[i][j] & 0x00ffffff;
              //  Color v=new Color(PixelArray[i][j]);
                System.out.print(" , "+var+" => "+RetrivePixel[i][j]+" PixelArray "+PixelArray1[i][j]);
            }
            System.out.println();
        }
        System.out.println(Integer.toBinaryString(222));
        System.out.println(Integer.signum(93226268));;
         Color c=new Color(16);
       System.err.println(c.getRGB());
//        System.out.println(c.getRed()+" "+c.getGreen()+" "+c.getBlue()+" "+c.getAlpha());
        System.out.println(c.toString());
        int colorint =-16645630 & 0x00ffffff;//c.getRed()+c.getGreen()+c.getBlue()+c.getAlpha();
        System.out.println(" colorint "+colorint);
        }
        catch(Exception ee){
            ee.printStackTrace();
        }
    }

    public static void main(String args[]){
        ConstructImage c=new ConstructImage();
    }
}
4

0 回答 0