I have created a custom ImageView and in its onDraw method I need to draw some bitmaps based on user interaction like touch. Everything is working fine however slowly as I start adding more and more bitmap the application really slows down.

As you can see, I am redrawing all the bitmaps in the List everytime onDraw is called naturally when the number of bitmap exceeds say 4-5 the operation becomes very expensive and slows the application down.

Any solution to this proble as to how can this be optimized?

Can calling drawBitmap in a different thread make the operation less expensive?

Is there a way to keep a copy of the previous canvas and then simply restore it in onDraw rather than drawing all the bitmaps again?

The question essentially is refreshing the View with lots of dynamic images on it and its optimization.

2 Answers
2

You should create a Bitmap which size must be equal to the ImageView's image size and draw all the bitmaps from the bitmapList on this bitmap only once. On every onDraw() call you should draw only this bitmap. When the bitmapList changes, this additional bitmap must be recreated.

Thanks for the response I tried it and it does improve the performance however using traceview shows that now the method that creates bufferCanvas takes that time. Although this improves the performance as now I do not need to draw all bitmaps everytime onDraw is called, its still slow when I need to refresh the buffers.
–
PravinCGJun 1 '11 at 14:57

You can try to create a new buffer every time you need to refresh it and you can do it from a separate thread. Think it will make your app run faster.
–
MichaelJun 1 '11 at 15:35