我正在尝试从图像中获取rgb
值,但即使在同一像素上也总是得到不同的值。
我使用了以下代码:
imageView=(ImageView)findViewById(R.id.imageView);
final Bitmap bitmap = ((BitmapDrawable)
imageView.getDrawable()).getBitmap();
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v,MotionEvent event) {
int x= (int)event.getX();
int y= (int)event.getY();
int pixel = bitmap.getPixel(x, y);
int redValue = Color.red(pixel);
int greenValue = Color.green(pixel);
int blueValue = Color.blue(pixel);
// Toast.makeText(MainActivity.this,String.format("#%02x%02x%02x", redValue,
greenValue, blueValue), Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, "R= " + redValue + "G= " + greenValue +
"B= " + blueValue, Toast.LENGTH_LONG).show();
// Toast.makeText(MainActivity.this,""+x+"\tY "+y,Toast.LENGTH_LONG).show();
return false;
}
});