-1

With link to my previous question of Moving Circle on Live Wallpaper. I am moving a circle with new bitmap each time with circle drawn on it on new position i.e. (x,y). But it doesn't seems to me a good way of doing it, so I am thinking that is it possible to remove a circle/bitmap drawn on it in live wallpaper canvas?

if yes then please share some code/link.

Community
  • 1
  • 1
Avtar Guleria
  • 2,126
  • 3
  • 21
  • 33
  • It's definitely possible. In fact in your other question you did it. What doesn't seem good about your approach? are you hitting performance issues? You need more detail. – BoredAndroidDeveloper Mar 20 '12 at 12:55

1 Answers1

0

If you're hitting performance issues, at this point in your code...

BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPurgeable = true;
            bitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.aquarium, options);

...you are decoding a bitmap every frame. That is expensive and should be avoided.

Instead read in the bitmap once and then use it to draw to your canvas every frame.

As well, you should try not to instantiate anything in the draw loop. Everything you create there has to be Garbage Collected and that will slow things down. Anything that is an object try to instantiate outside of the draw loop. So the other thing you could do to make this perform a little faster is to do this in the constructor:

Paint paint = new Paint();
BoredAndroidDeveloper
  • 1,251
  • 1
  • 11
  • 26
  • Thanks, but please tell me can i also delete/remove previously drawn object on canvas in live wallpaper or i have to redraw the complete canvas again and again. – Avtar Guleria Mar 21 '12 at 06:27
  • I've looked around. In general it looks like you have to re-draw the complete canvas every frame. Otherwise you could pull out where the circle has been drawn from your bitmap, turn it into a new bitmap, and then draw just that section to the old canvas. But that sounds like much more work than what is needed. I think if you pull out the decoding from the draw loop that you will see massive performance increases. – BoredAndroidDeveloper Mar 21 '12 at 16:52
  • Thanks for your precious time and I have implemented all your suggestions and it increases the performance tremendously. – Avtar Guleria Mar 22 '12 at 03:58