我能够在图像中创建一个点但是当我将坐标设为touchx时,在canvas.drawCircle(touchX,touchY,2,paint)中触摸我无法在我所在的地方创建圆点。已触摸,此功能应该只在点击图像时工作,但它的创建点,当我触摸图像外,当我触摸屏幕图像正在缩放...我wnat图像不应该缩放,应该创建点只触摸图像。亲切帮助...
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;
}
});
答案 0 :(得分:1)
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;
}
});