0

我正在尝试在加载到我的应用程序中的 JPEG 图像上绘制圆圈。当用户触摸某个位置时,应在该位置绘制圆圈。我怎样才能做到这一点?

4

1 回答 1

2

看到这个链接

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


         touchX=touchX- image.getWidth() / 2;
         touchY=touchY- image.getHeight() / 2;

        canvas.drawCircle(touchX, touchY, radius, paint);
        System.out.println("Drew a circle at "+touchX+" " + touchY+" with a radius of "+radius+".");
        return image;
    }
于 2012-06-30T18:49:55.217 回答