Clear circle Bitmap

113 Views Asked by At

I have loaded a floor plan image and converted it into a Bitmap. And I have a circle drawn onto that floor plan image. This circle shows the current position of this user on the floor plan.

The problem is, when it comes a slow response from the server, multiple circle are drawn on the floor plan

Here is my code :

 public void onServiceUpdate(ServiceState state) {
 final int i, j;
        i = state.getImagePoint().getI();
        j = state.getImagePoint().getJ();
  ImageView imageView = (ImageView) findViewById(R.id.imageView);
        imageView.buildDrawingCache();
        Bitmap bitmap = imageView.getDrawingCache();
        final ImageView imageFloor = (ImageView) findViewById(R.id.imageView);
        final Bitmap bitmapCircle = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
        Canvas canvas = new Canvas(bitmapCircle);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(10);
        canvas.drawBitmap(bitmap, new Matrix(), null);
        canvas.drawCircle(i, j, 10, paint);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                imageFloor.setImageBitmap(bitmapCircle);
            }
        });

and this is method calling floor plan image from indooratlas server.

public void loadFloorPlanImage(FloorPlan floorPlan) {
    BitmapFactory.Options options = createBitmapOptions(floorPlan);
    FutureResult<Bitmap> result = mIndoorAtlas.fetchFloorPlanImage(floorPlan,options);
    result.setCallback(new ResultCallback<Bitmap>() {
        @Override
        public void onResult(final Bitmap result) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ImageView imageView = (ImageView) findViewById(R.id.imageView);
                    imageView.setImageBitmap(result);
                    log("onResult LoadFloorPlanImage");
                }
            });
        }

is there any ideas or some advice how to clear the circle inside floor plan bitmap ?

1

There are 1 best solutions below

2
On

You could do like this:

onServiceUpdate(...){
    final ImageView imageFloor = (ImageView) findViewById(R.id.imageView);
    imageFloor.setVisibility(View.GONE);
    ....
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
             imageFloor.setVisibility(View.VISIBLE);
             imageFloor.setImageBitmap(bitmapCircle);

But your question isn't very clear, I would not be surprised if I didn't understand what you meant