Kosh
Kosh

Reputation: 6334

clear the canvas draw programmatically Android

well i'v problem with canvas.draw() i'm having multiple frames to overlay on the same bitmap . and i succeed to do this. but the problem is when now it comes to apply another frame using the same methods but different border , the border overlay the old ones.

    void hm(){
    Bitmap border = BitmapFactory.decodeResource(getResources(), R.drawable.vignette2);
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    change = Bitmap.createScaledBitmap(change, width, height, false);
    Canvas canvas = new Canvas(change);
    Bitmap scaledBorder = Bitmap.createScaledBitmap(border,width,height, false);
    canvas.drawBitmap(scaledBorder, 0, 0,null);
    //canvas.drawBitmap(k, 0, 0, null);
    view.setImageBitmap(change);
    }

and here is the other method:

    void hm1(){
    Bitmap border = BitmapFactory.decodeResource(getResources(), R.drawable.white);
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    change = Bitmap.createScaledBitmap(change, width, height, false);
    Canvas canvas = new Canvas(change);
    Bitmap scaledBorder = Bitmap.createScaledBitmap(border,width,height, false);
    canvas.drawBitmap(scaledBorder, 0, 0,null);
    //canvas.drawBitmap(k, 0, 0, null);
    view.setImageBitmap(change);
    } 

now when i click on button1 the overlay applies to the view. and when i click on button2 it also applies to the view but it doesn't destroy the old border("the Overlay image"). i know that i should use different bitmap to handle every view of the imageview. but i'm using save button which will save the Bitmap change which means i want to apply the borders on this image and display it. without overlaying the old borders.
for example i'm using QuickActionand here is how i'm trying to accomplish the clicks.

                if (actionId == border0){
                hm();
                } 

             if (actionId == border1 ){
                 hm1();
                } 

              if (actionId == border2 ){
              }

it works but as i said it overlay the old ones . any help will be thankful. thanks in advance. Solved it tomorrow i will post the Answer :).

Upvotes: 0

Views: 1171

Answers (1)

WarrenFaith
WarrenFaith

Reputation: 57672

Well you create a new bitmap based on the old one with this line:

change = Bitmap.createScaledBitmap(change, width, height, false);

So make sure that you somehow reset the change bitmap with the original:

change = Bitmap.createScaledBitmap(originalBitmap, width, height, false);

Upvotes: 2

Related Questions