Java 编码后,rgb值会自动受到干扰

Java 编码后,rgb值会自动受到干扰,java,rgb,Java,Rgb,我正在构建一个编码器,在这里我上传一个图像,然后我获取它的第一个像素,即位置(0,0)处的像素。我提取它的蓝色分量,并重置它与原始值不同的值。 现在,当我尝试检查我重置的值时,该值不匹配 例如:如果最初的值是120,我将其重置为49,当我检查值时,它给出了111,这是不正确的…有人能帮忙吗? 图像存储在p1中 在编码器中 String e="00110001"; int bi= Integer.parseInt(e,2); int r=p1.get(0,0).getRed(); int g=p1

我正在构建一个编码器,在这里我上传一个图像,然后我获取它的第一个像素,即位置(0,0)处的像素。我提取它的蓝色分量,并重置它与原始值不同的值。 现在,当我尝试检查我重置的值时,该值不匹配 例如:如果最初的值是120,我将其重置为49,当我检查值时,它给出了111,这是不正确的…有人能帮忙吗? 图像存储在p1中

在编码器中

String e="00110001";
int bi= Integer.parseInt(e,2);
int r=p1.get(0,0).getRed();
int g=p1.get(0,0).getGreen();
Color clr= new Color(r,g,bi);
p1.set(0,0,clr);
现在我保存这个图像

在解码器中,我上传保存的图像p11

int pp=p11.get(0,0).getBlue();
pp和bi不匹配 请帮忙

set和get的代码

public Color get(int x, int y) {
    if (x < 0 || x >= width())  throw new IndexOutOfBoundsException("x must be between 0 and " + (width()-1));
    if (y < 0 || y >= height()) throw new IndexOutOfBoundsException("y must be between 0 and " + (height()-1));
    if (isOriginUpperLeft) return new Color(image.getRGB(x, y));
    else                   return new Color(image.getRGB(x, height - y - 1));
}


public void set(int x, int y, Color color) {
    if (x < 0 || x >= width())  throw new IndexOutOfBoundsException("x must be between 0 and " + (width()-1));
    if (y < 0 || y >= height()) throw new IndexOutOfBoundsException("y must be between 0 and " + (height()-1));
    if (color == null) throw new NullPointerException("can't set Color to null");
    if (isOriginUpperLeft) image.setRGB(x, y, color.getRGB());
    else                   image.setRGB(x, height - y - 1, color.getRGB());
}
公共颜色获取(int x,int y){
如果(x<0 | | x>=width())抛出新的IndexOutOfBoundsException(“x必须介于0和“+(width()-1)”之间);
如果(y<0 | | y>=height())抛出新的IndexOutOfBoundsException(“y必须介于0和“+(height()-1))之间);
if(isOriginUpperLeft)返回新颜色(image.getRGB(x,y));
否则返回新颜色(image.getRGB(x,height-y-1));
}
公共无效集(整数x、整数y、颜色){
如果(x<0 | | x>=width())抛出新的IndexOutOfBoundsException(“x必须介于0和“+(width()-1)”之间);
如果(y<0 | | y>=height())抛出新的IndexOutOfBoundsException(“y必须介于0和“+(height()-1))之间);
如果(color==null)抛出新的NullPointerException(“不能将color设置为null”);
if(isOriginUpperLeft)image.setRGB(x,y,color.getRGB());
setRGB(x,height-y-1,color.getRGB());
}

为什么不在
p1.set
中使用you
clr
对象?p1的类型是什么?@Trichoko这是一个类型错误..我更正了它。非常感谢。剩下的问题是picture…我创建了一个类来存储imagesNot足够的信息。p1是什么?您能显示p1.set(int,int,Color)和p1.get(int,int)的代码吗?