如何在android中的触摸事件上获取图像的点(或像素)的颜色

Shi*_*ade 14 android image pixel colors imageview

我想获得我将在Android中触摸图像的点或像素的颜色.我在网上搜索了很多,却一无所获.请有人帮帮我.

roa*_*ter 34

试试这个:

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;
        }
   });
Run Code Online (Sandbox Code Playgroud)

  • 请注意图像可以缩放.解决方案:http://stackoverflow.com/questions/12496339/android-imageview-get-pixel-color-from-scaled-image (5认同)