我使用以下代码设置具有新值的图像数组的初始8 * 8像素位置,但不幸的是它返回初始值。示例我已更改初始值 具有16的图像阵列的8 * 8值并构造图像。 当我检索那个图像并读取前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();
}
}