绘制循环,即用户触摸屏幕 [英] Draw circle where user touches screen

查看:116
本文介绍了绘制循环,即用户触摸屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我画的地方用户触摸图像视图一个圆。它借鉴了一圈很好,但它绝不是用户接触。它始终是关闭的很多左侧。这里是code:

I draw a circle where the user touches a image view. It draws the circle fine, but it is not where the user touches. It is always off the left by a lot. Here is the code:

获取触摸:

image.setOnTouchListener(new OnTouchListener() {

    public boolean onTouch(View arg0, MotionEvent arg1) {
        System.out.println("Touch recieved at "+arg1.getX() + " " + arg1.getY());
        touchX =  (arg1.getX());
        touchY =   (arg1.getY());
        System.out.println("Touch recieved at "+touchX + " " + touchY);
        image.setImageBitmap(createImage());

        return true;
    }
});

和在图像上图:

public Bitmap createImage(){
        Bitmap image = bmp.copy(Bitmap.Config.RGB_565, true);
        Canvas canvas = new Canvas(image);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GREEN);
        canvas.drawCircle(touchX, touchY, radius, paint);
        System.out.println("Drew a circle at "+touchX+" " + touchY+" with a radius of "+radius+".");
        return image;
    }

任何想法?

推荐答案

有一个看的你好圈例如

这篇关于绘制循环,即用户触摸屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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