如何在android中的触摸事件上在图像的点(或像素)处获取颜色 [英] how to get color at the spot(or pixel) of a image on touch event in android
本文介绍了如何在android中的触摸事件上在图像的点(或像素)处获取颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取我将在 Android 中触摸图像的点或像素的颜色.我在网上搜索了很多,但一无所获.请任何人帮助我.
I want to get the color of the spot or pixel where I will touch a image in Android. I searched a lot on net, but got nothing. Please anyone help me.
推荐答案
试试这个:
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;
}
});
这篇关于如何在android中的触摸事件上在图像的点(或像素)处获取颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文