Android
Android

Reputation: 9033

Android get Bitmap from canvas

In One of my application i need to get bitmap form the canvas....

Actually what is my app is...

There are 2 canvas on view...

I am erasing Bitmap from canvas1 so that image from canvas 2 is displaying... (Put trasperent canvas)

Now when user presses save button it must get bitmap from canvas1 only not from view Actually the code is like this

public void onClick(View v) {

    Bitmap editedImage = Bitmap.createBitmap(drawView
                        .getDrawingCache());
    editedImage = Bitmap.createScaledBitmap(editedImage, 200, 300,
                        true);
    if (editedImage != null) {
        //Intent intent = new Intent();
        //intent.putExtra(ChooseActivity.BITMAP, editedImage);
        // AddReportItemActivity.mPhoto =
        // drawView.getDrawingCache();
        //setResult(SUCCESS, intent);
        //  finish();
        Bitmap bbicon;

But it not Bitmap that i actually want

My question is How to get bitmap from canvas..? Or any other solution?

I have visited this link But not able to understand Plz help

Upvotes: 1

Views: 5496

Answers (1)

Samuel Urbanowicz
Samuel Urbanowicz

Reputation: 834

I am not sure what you specificaly want to achieve, however general pattern is to do it like this:

  1. Create a bitmap Bitmap.createBitmap()
  2. Create a canvas object pointing that bitmap Canvas(Bitmap)
  3. Draw any Bitmap objects to canvas (for ex. canvas.drawBitmap(getResources(), R.drawable.my_drawable), 0f, 0f, null); )
  4. Use the bitmap

Upvotes: 3

Related Questions