本文介绍了负灰度值 - 位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的code能为灰度图像的R,G,B值(它们都将是相同的)
但输出给了我负值。
I am using the following code to get the R,G,B values for a grayscale image(they all will be the same)But the output gives me negative values.
为什么会这样?我完全糊涂了。
Why is this so? I am totally confused.
for (int i=0;i<bb.getWidth();i++){
for (int j=0;j<bb.getHeight();j++){
long temp=bb.getPixel(i, j);
int a=(int)temp;
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(a );
byte[] result = b.array();
Log.d("gray value is=", String.valueOf((int)result[1]));
// Log.d("gray value is=", String.valueOf(getLastBytes(a)));
}
}
下面结果[1]应该对应于R的价值。那么它是如何负?
Here result[1] should correspond to the 'R' value. So how is it negative?
推荐答案
试试这个
long temp=bb.getPixel(i, j);
R = Color.red(temp);
G = Color.green(temp);
B = Color.blue(temp);
这篇关于负灰度值 - 位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!