我在用戶觸摸圖像視圖的地方繪製了一個圓圈。它可以很好地畫圓,但不是用戶觸摸的地方。它總是在左邊很多。下面是代碼:在用戶觸摸屏幕的地方繪製圓圈
獲取觸摸:
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;
}
任何想法?
嗯,使它更接近......但還是關閉?它就像你在屏幕上移動得越遠,越遠。 – 2012-01-19 03:08:34