Java 设置像素的红色值,不设置RGB
我正在尝试设置BuffereImage的红色、绿色或蓝色值。 之后,我将检索该红/绿/蓝值,然后处理该值 但我的问题是当我这样做的时候Java 设置像素的红色值,不设置RGB,java,colors,rgb,pixel,bufferedimage,Java,Colors,Rgb,Pixel,Bufferedimage,我正在尝试设置BuffereImage的红色、绿色或蓝色值。 之后,我将检索该红/绿/蓝值,然后处理该值 但我的问题是当我这样做的时候 Color cipherColor = new Color(cipherDecimal[offColor], cipherDecimal[offColor], cipherDecimal[offColor]); int cipherColorInt = cipherColor.getRGB(); stegoImage.setRGB(x, y, cipherCo
Color cipherColor = new Color(cipherDecimal[offColor], cipherDecimal[offColor], cipherDecimal[offColor]);
int cipherColorInt = cipherColor.getRGB();
stegoImage.setRGB(x, y, cipherColorInt);
然后,我对这个值很好奇…所以我添加了一些代码来查看设置RGB前后的RGB值
Color cipherColor = new Color(cipherDecimal[offColor], cipherDecimal[offColor], cipherDecimal[offColor]);
int cipherColorInt = cipherColor.getRGB();
stegoImage.setRGB(x, y, cipherColorInt);
int tesColor = stegoImage.getRGB(x, y);
System.out.println(cipherColorInt + "\t" + tesColor);
关于stegoImage的信息
BuffereImage stegoImage=新的BuffereImage(img.getWidth(null),
img.getHeight(null)+h,buffereImage.TYPE_BYTE_GRAY)
img只是一个普通的图像
它将设置RGB值几乎正确。几乎,因为一些价值观发生了变化。这是:
-------- RGB after and before----------
before after
-6052957 -6052957
-7303024 -7303024
-10855846 -10855846
-11053225 -11119018 --> changed
-3158065 -3158065
-2500135 -2500135
-13027015 -13092808 --> changed
-5658199 -5658199
-131587 -131587
-12500671 -12566464 --> changed
-5658199 -5658199
-16448251 -16777216 --> changed
-5526613 -5526613
-8553091 -8553091
-1579033 -1579033
-3421237 -3421237
请帮帮我:)
现在,如果你知道没有setRGB甚至BuffereImage设置红/绿/值的其他方法,请告诉我。
或者,如果您知道是什么导致值发生更改或如何修复它,请告诉我
谢谢因为您知道您的图像是
类型\字节\灰色
,它将具有线性灰度颜色空间和字节数据缓冲区,因此您可以获取数据缓冲区,将其转换为数据缓冲区
,并直接访问本机灰色字节值:
DataBufferByte buffer = (DataBufferByte) stegoImage.getRater().getDataBuffer();
byte[] data = buffer.getData(); // signed gray values in linear gray space
// Access each pixel
byte signedGrayPixelValue = data[x + y * stegoImage.getWidth()]; // [-128...127]
// Alternatively
int grayPixelValue = data[x + y * stegoImage.getWidth()] & 0xff; // [0...255]
使用
setRGB/getRGB
的问题可能是,这些方法假定值在sRGB颜色空间中,因此并不总是与线性灰色空间相对应(即,会出现舍入错误)。您的stegoImage对象是什么类型的?哦,对了,对不起……它是BuffereImage stegoImage=new BuffereImage(img.getWidth(null),img.getHeight(null)+h,buffereImage.TYPE_BYTE_GRAY);img只是一个普通的图像对不起,那个数据变量包含什么?我有点不知道DataBufferByteIt的灰度像素值。请参阅更新。如果你需要RGB值,你可以从新颜色(灰度像素值,灰度像素值,灰度像素值)创建一个
,但这有点不必要。哇,谢谢你这么好的解释,这对我来说是新的哈哈哈,因为你说问题是因为键入了\u BYTE\u GRAY。然后我也试着不使用它……它很管用哈哈