【发布时间】:2013-02-17 10:52:52
【问题描述】:
我想获取我将在 Android 中触摸图像的点或像素的颜色。我在网上搜索了很多,但一无所获。请任何人帮助我。
【问题讨论】:
标签: android image colors imageview pixel
我想获取我将在 Android 中触摸图像的点或像素的颜色。我在网上搜索了很多,但一无所获。请任何人帮助我。
【问题讨论】:
标签: android image colors imageview pixel
试试这个:
final Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
imageView.setOnTouchListener(new 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);
//then do what you want with the pixel data, e.g
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
return false;
}
});
【讨论】:
您可以计算被点击像素的图像坐标并从图像数据中读取像素,例如
Bitmap.getPixel(xcord,ycord)
【讨论】: