Reputation: 215
I have written the code to draw the text on image its working fine I am capturing the image in potrait mode but application crashes when I am capturing the image in landscape mode,I am getting exception Java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
Canvas canvas = new Canvas(photo);
Typeface tf = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Style.FILL);
paint.setTypeface(tf);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(12);
canvas.drawBitmap(photo, 0, 0, paint);
canvas.drawText(topaste, 10, 115, paint);
image.setImageBitmap(photo);
Upvotes: 1
Views: 867
Reputation: 12229
Basically the canvas object needs a fresh bitmap to draw to, passing in your immutable image defeats the point of the later draw operation. The following code creates a new bitmap for the canvas. You will need to replace the width and height variables to match your use case:
Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
Canvas canvas = new Canvas(photo);
Upvotes: 1