我正在处理获取图像并将其显示在图像视图中的应用程序。当用户调整屏幕时,我希望在再次触摸屏幕后,该圆圈覆盖的图像(定位的圆圈是触摸屏幕)在该区域保持颜色。 我能够在图像上绘制圆圈但是当再次触摸屏幕时,图像不会保持颜色。
class DrawingView extends SurfaceView {
private final SurfaceHolder surfaceHolder;
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Bitmap bitmap1 = null;
private Bitmap bitmap2 = null;
private final Point node = new Point();
public DrawingView(Context context) {
super(context);
surfaceHolder = getHolder();
paint.setColor(Color.RED);
paint.setStyle(Style.FILL);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
if (surfaceHolder.getSurface().isValid()) {
node.x= (int)event.getX();
node.y = (int)event.getY();
Canvas canvas = surfaceHolder.lockCanvas();
bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.nic_eyes);
canvas.drawBitmap(bitmap1, 0, 0, null);
canvas.drawCircle(event.getX(), event.getY(), 50, paint);
bitmap2 = bitmap1.copy(bitmap1.getConfig(),true);
surfaceHolder.unlockCanvasAndPost(canvas);
photo = bitmap2;//photo is used for saving the modified image into galery
}
}
return false;
}
}
有什么建议吗?