0

I am trying to create an image save and retrieve feature in android. The code I have for creating a jpg file from canvas is as below

Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); 

I am trying to read the jpg file and create image on canvas using

Bitmap bMap = BitmapFactory.decodeStream(buf); Bitmap workingBitmap = Bitmap.createBitmap(bMap); Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); view.mybitmap = mutableBitmap; view.onDraw(view.Canvas); 

The code I have in onDraw is

canvas.drawBitmap(view.mybitmap, 0, 0, view.myPaint); 

This draws the bitmap on canvas correctly from the stored jpg file but I am not able to draw anything on the canvas after that. Has it loaded a immutable bitmap image on canvas which I am not able to edit?

Any help will be appreciated! Thanks!

4
  • extend SurfaceView (or View) and override onDraw(Canvas canvas) Commented Aug 11, 2014 at 22:12
  • What does it mean 'but I am not able to draw anything on the canvas after that'. If your onDraw logic has extra work to do, you need to call invalidate on your View when you need to draw. Commented Aug 11, 2014 at 22:44
  • @Vladimir: It means when I load the bitmap on the canvas, I cannot edit the drawing. Commented Aug 12, 2014 at 0:12
  • @user2365568: As I have mentioned in the question, I have already overridden onDraw method. Do you want me to add something else in it? Commented Aug 12, 2014 at 0:15

1 Answer 1

0

You shouldn't need to be calling the ondraw method directly like you are doing currently. For a custom view class all you should need to be calling is view.invalidate(); This will auto call the ondraw method and re-draw the canvas. You will probably need to update the logic in your ondraw method to handle the cases where you want to draw additional things on the canvas.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.