Animation lagging using canvas clip paths

  • Replies:0
Shubhadeep Chaudhuri
  • Forum posts: 1

Aug 29, 2012, 9:49:01 PM via Website

Well I'm trying to create this kind of animation where an image emerges from the center

And this is the code I'm using
1int size = 5;
2Paint p = new Paint();
3Path path = new Path();
4
5private void animate() {
6 for (int i = 0; i < 20; i++) {
7 path.addCircle(centerX, centerY, size, Path.Direction.CCW);
8 canvas.clipPath(path);
9 canvas.drawBitmap(bmp, 0, 0, null);
10 path.reset();
11 int incr = size;
12 while (p.getAlpha() != 0) {
13 incr += 1;
14 p.setAlpha(p.getAlpha() - 5);
15 path.addCircle(centerX, centerY, incr, Path.Direction.CCW);
16 canvas.clipPath(path, Op.UNION);
17 canvas.drawBitmap(bmp, 0, 0, p);
18 path.reset();
19 }
20 size += 10;
21 }
22}

But the animation is very lagging. I understand it is because of the amount of modifications to the clip path in each frame.
So an alternative way to do this would really help. I couldn't think of anything else.

— modified on Aug 29, 2012, 9:49:54 PM

Reply