gpt4 book ai didi

java - 绘制图像后设置的像素发生变化

转载 作者:行者123 更新时间:2023-12-01 09:33:03 24 4
gpt4 key购买 nike

在我的项目中,获取图像的每个像素值,然后对像素执行解密并为像素设置新值。但是,在使用更改的像素值创建新图像后,新图像不能包含与我更改的像素值相同的像素值。主要像素值发生变化。如何解决这个问题呢。我的代码是

     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

如何在创建图像后不更改像素值的情况下创建图像。谢谢。

最佳答案

尝试使用无损格式,例如 PNG。 JPG 在压缩过程中改变了像素值,因此无法完全按照创建时的方式读取。

关于java - 绘制图像后设置的像素发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39240275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com