java - Android 在可触摸区域绘制

标签 java android image touch draw

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

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

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

触摸之前:

Before Touching

触摸后:

After Touching

我并不是在寻找整个解决方案,而是在寻找一些提示,也许还有一些 fragment 。 提前非常感谢;)

编辑: 高级问题:我还想测量字母上方的触摸效果如何,如果不够好我想知道,也许可以做可触摸区域和不可触摸区域,并数出哪一个并得出百分比?谢谢

最佳答案

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

关于java - Android 在可触摸区域绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906376/

相关文章:

java - 无法在未调用 Looper.prepare android 的线程内创建处理程序

java - float 数学类的替代品

java - org.hibernate.exception.ConstraintViolationException : Could not execute JDBC batch update

java - Android中的Facebook登录弹出两个登录界面

java - 当网络服务中的纬度和经度发生变化时,如何移动谷歌地图中的标记?

android - 如何从MP4中逐帧获取? (媒体编解码器)

java - 更新我的项目时遇到问题,图像 BLOB 格式 [JAVA]

javascript - 如何: two divs floating left one static and the other responsive

python - OpenCV 寻找图像的紧密匹配

java - c3p0 连接池不支持 20 个用户