在ImageView上绘制圆形的坐标错误。

3

我正在尝试在ImageView上绘制一个圆形。圆形被绘制出来了,但坐标错误。

 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(),圆圈在位图的左上方绘制得更高。


你能在drawCircle之前加上System.out.println(x+","+y);并告诉我你得到了什么吗? - Adithya Surampudi
我获取了我点击的位置的坐标。如果我在左上角点击,我会得到0 0的坐标。坐标是正确的,但位置是错误的。 - n1n3b1t
1个回答

1

问题出在位图大小上。 文件的原始大小是正确的。但在此之后

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

尺寸增加了15-20%


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接