1

我可以在图像中创建一个点,但是当我在 canvas.drawCircle(touchX,touchY, 2, paint) 中将坐标指定为 touchx,touchy 时,我无法在我触摸过的地方创建圆点,还有这个功能应该仅在单击图像时起作用,但是当我触摸图像外部时它的创建点以及当我触摸屏幕时图像正在缩放...我想不应该缩放的图像并且应该仅在触摸图像时创建点。 .请帮助...

imageView.setOnTouchListener(new View.OnTouchListener() {                    
 @Override
public boolean onTouch(View v, MotionEvent event) {               
                touchX = (int) (event.getX());
                touchY = (int) (event.getY());                
                ImageView imageView = (ImageView) findViewById(R.id.imageView2);
                Bitmap bitMap = Bitmap.createBitmap(100,100, Bitmap.Config.ARGB_8888);
                bitMap = bitMap.copy(bitMap.getConfig(), true);     
                Canvas canvas = new Canvas(bitMap);                
                Paint paint = new Paint();                       
                paint.setColor(Color.BLUE);
                paint.setStyle(Paint.Style.FILL);
                paint.setAntiAlias(true);
                imageView.setImageBitmap(bitMap);      
                imageView.setBackgroundResource(R.drawable.image_map);
                canvas.drawCircle(50, 60, 2, paint);
                imageView.invalidate();
                return true;
            }
        });
4

1 回答 1

2
        ivImage = (ImageView) findViewById(R.id.ivImage);
        final Bitmap bitmap = ((BitmapDrawable)ivImage.getDrawable()).getBitmap().copy(Config.ARGB_8888, true);
        ivImage.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                int touchX = (int)(event.getX());
                int touchY = (int)(event.getY());
                Canvas canvas = new Canvas(bitmap);
                Paint paint = new Paint();
                paint.setColor(Color.GREEN);
                canvas.drawCircle(touchX, touchY, 2, paint);    // for circle dot
                //canvas.drawPoint(touchX, touchY, paint);  // for single point
                ivImage.setImageBitmap(bitmap);
                ivImage.invalidate();
                return true;
            }
        });
于 2015-07-11T20:14:42.900 回答