我如何获得 android 油漆(手写笔)尺寸? [英] How do I get android paint(stylus) size?

查看:52
本文介绍了我如何获得 android 油漆(手写笔)尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要检测手写笔大小的App,比如我用我的手(比较宽)画画,返回null,如果我用手写笔(比较小)画画,执行draw.Point方法.

I am developing an App that need to detect the stylus's size, for instance, if I use my hand(relatively wide) to draw, return null, if I use the stylus(relatively small) to draw, execute draw.Point method.

我不知道如何检测这个.请帮忙谢谢.

I have no idea how to detect this. Please for help thanks.

我的代码列表如下.

public PaintView(Context context) {
        super(context);
        paint=new Paint(Paint.DITHER_FLAG);
        bitmap = Bitmap.createBitmap(MainActivity.widthPixels, MainActivity.heightPixels, Bitmap.Config.ARGB_8888);
        canvas=new Canvas();
        canvas.setBitmap(bitmap);

        paint.setStyle(Paint.Style.STROKE);
        //float size = paint.getStrokeWidth();
        paint.setStrokeWidth(5);
        paint.setColor(Color.RED);
    }

@Override
    protected void onDraw(Canvas canvas) {
        canvas.drawBitmap(bitmap,0,0,null);
    }

@Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction()==MotionEvent.ACTION_MOVE) {
            canvas.drawLine(mov_x, mov_y, event.getX(), event.getY(), paint);
            invalidate();
        }
        if (event.getAction()==MotionEvent.ACTION_DOWN) {
            mov_x=(int) event.getX();
            mov_y=(int) event.getY();
            canvas.drawPoint(mov_x, mov_y, paint);
            invalidate();
        }
        mov_x=(int) event.getX();
        mov_y=(int) event.getY();
        return true;
    }

推荐答案

您可以使用 MotionEvent.getSize() 方法来检测手指和手写笔触摸的大小,然后创建规则如何确定导致触摸的原因.另外 MotionEvent.getPressure() 可能有用.

You can use MotionEvent.getSize() method to detect sizes of finger and stylus touch and then create rule how to determine what caused the touch. Also MotionEvent.getPressure() may be useful.

这篇关于我如何获得 android 油漆(手写笔)尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆