如何在android上的JPEG图像上绘制一个红色圆圈

时间:2012-06-30 18:46:36

标签: android

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

1 个答案:

答案 0 :(得分:2)

请参阅此link

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