【问题标题】:how to get color at the spot(or pixel) of a image on touch event in android如何在android中的触摸事件上获取图像的点(或像素)颜色
【发布时间】:2013-02-17 10:52:52
【问题描述】:

我想获取我将在 Android 中触摸图像的点或像素的颜色。我在网上搜索了很多,但一无所获。请任何人帮助我。

【问题讨论】:

    标签: android image colors imageview pixel


    【解决方案1】:

    试试这个:

    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;
            }
       });
    

    【讨论】:

    【解决方案2】:

    您可以计算被点击像素的图像坐标并从图像数据中读取像素,例如

    Bitmap.getPixel(xcord,ycord)
    

    【讨论】:

    • 我需要在缩放图像后获取像素。我尝试了所有解决方案,但只得到白色作为回报
    猜你喜欢
    • 1970-01-01
    • 2010-11-20
    • 2010-11-08
    • 2016-05-07
    • 1970-01-01
    • 2014-03-14
    • 2013-02-17
    • 1970-01-01
    相关资源
    最近更新 更多