【问题标题】:Android Draw at Touchable AreasAndroid 在可触摸区域绘图
【发布时间】:2014-02-20 11:27:43
【问题描述】:

我想获得一些关于如何执行诸如画窗应用程序画笔之类的提示。

会有一个具有可触摸区域的图像(如何在图像上定义可触摸区域?),当用户触摸这些可触摸区域时,我想像用不同颜色的画笔一样绘制(如何在 android 上绘制?哪个我应该使用小部件吗?imageview?)

这里有一些图片可以提供帮助。

触摸前:

触摸后:

我不是在寻找完整的解决方案,我在寻找一些提示,也许还有一些 sn-ps。 提前非常感谢;)

编辑: 进阶问题:我也想测量一下字母上面的触摸效果有多好,如果不够好我想知道,也许做可触摸区域和不可触摸区域,并计算哪一个并做百分比?谢谢

【问题讨论】:

    标签: java android image touch draw


    【解决方案1】:
    One way is use get the color where user touched and compare that with the touchable area here (gray) in your case. If the pixel color is gray means user is touching at right spot if white that means untouchable area 
    
    You can get the pixel color like this-
    
    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;
            }
       });
    
    
    Hope this helps
    

    【讨论】:

    • 这将有助于 ofc !以及如何绘制黄色刷子之类的东西?谢谢。