0

I want to add some text on top of an image. I read the image from the sd card and set it to a Bitmap variable.

Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

Then I added it to a canvas. The code I used is given below,

Canvas c = new Canvas(myBitmap);

But when I added this line, the app crashed at that point. Why is it and how can i solve this ??

Note : Above mention code lines are inside onActivityResult method.

Optimus
  • 415
  • 4
  • 19
  • Try this link http://stackoverflow.com/questions/2172523/draw-object-image-on-canvas – G_S Aug 14 '12 at 17:16

1 Answers1

0

You app crash because your

BitmapFactory.decodeFile

return a immutable bitmap and public Canvas (Bitmap bitmap) only accept a mutable bitmap.

To solve your problem you must convert your immutable Bitmap into mutable see here the method

If you target only >= API 11 , you can use

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
Community
  • 1
  • 1
SteveR
  • 2,496
  • 1
  • 24
  • 23