2011-06-20 42 views
2

我试图在ImageView上画一个圆。圆圈正在画,但有错误的坐标。ImageView上的drawCircle错误坐标

protected void onImageClicked(float x, float y, ImageView image) { 
     if (diff.isDifferenceClicked((int)x, (int) y)){ 

     BitmapDrawable bmd = (BitmapDrawable) image.getDrawable(); 
     Bitmap bm= bmd.getBitmap(); 

     Paint paint = new Paint(); 
     paint.setAntiAlias(true); 
     paint.setColor(Color.RED); 
     paint.setStyle(Paint.Style.STROKE); 

     Canvas canvas = new Canvas(bm); 
     canvas.drawCircle(x, y, 25, paint); 

     image.setImageBitmap(bm);} 

    } 

x和y是event.getX()event.getY() 和圆绘制更高,更为位图的左侧。

+0

你能不能做的System.out.println(X + “” + Y); drawCircle之前,让我知道你有什么? –

+0

我得到了我点击的地方的坐标。如果我点击左上角我有0 0.坐标是正确的,但地方是错误的。 – n1n3b1t

回答

1

问题在于位图大小。 文件的原始大小是正确的。但是,这

BitmapDrawable bmd = (BitmapDrawable) image.getDrawable(); 
    Bitmap bm= bmd.getBitmap(); 

大小延长了15-20%后