使用getPixel()方法提取的巨大负值 [英] Huge negative values extracted by using getPixel() method
问题描述
我正在开发一个图像处理应用程序的问题(这里是新手)。我试图通过使用 getPixel()
方法提取特定像素的值。
I am having a problem with an image processing app I am developing (newbie here). I am trying to extract the value of specific pixels by using the getPixel()
method.
我遇到了问题。我从这种方法得到的数字是一个巨大的负数,类似于-1298383。这是正常的吗?我该如何解决?
I am having a problem though. The number I get from this method is a huge negative number, something like -1298383. Is this normal? How can I fix it?
谢谢。
推荐答案
我不是专家,但是对我来说,看起来你得到的是十六进制值。也许你想要更像可理解的东西,比如每个RGB层的值。
I'm not an expert, but to me it looks like you are getting the hexadecimal value. Perhaps you want something more understandable like the value of each RGB layer.
将解包像素转换为RGB您应该执行以下操作的值:
To unpack a pixel into its RGB values you should do something like:
private short[][] red;
private short[][] green;
private short[][] blue;
/**
* Map each intensity of an RGB colour into its respective colour channel
*/
private void unpackPixel(int pixel, int row, int col) {
red[row][col] = (short) ((pixel >> 16) & 0xFF);
green[row][col] = (short) ((pixel >> 8) & 0xFF);
blue[row][col] = (short) ((pixel >> 0) & 0xFF);
}
在每个频道发生变化后,你可以打包像素返回。
And after changes in each channel you can pack the pixel back.
/**
* Create an RGB colour pixel.
*/
private int packPixel(int red, int green, int blue) {
return (red << 16) | (green << 8) | blue;
}
如果不是您想要的,请抱歉。
Sorry if it is not what you are looking for.
这篇关于使用getPixel()方法提取的巨大负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!