简体   繁体   中英

Android rotating bitmap around its center

I am trying to rotate regular bitmap around X, Y and Z axis using canvas and matrix. I could use OpenGL but I think it would be overkill to achieve such a simple effect as I am pretty sure this is possible using just canvas, bitmap and matrix.

I tried using camera and its rotateX, rotateY and rotateZ method and then applying that matrix to canvas but for some reason I can get it to rotate the bitmap around it center!

I can't find method to change the rotate origin so I decided to translate the camera so its at center of bitmap and afterwards translate it back, but whatever I try the bitmap doesn't get translated by its center... 图片

            camera.save();

            camera.translate(-(team.getWidth() / 2), (team.getHeight() / 2), 0f);

            rotateY += 1f;

            camera.rotateY(rotateY);

            camera.translate((team.getWidth() / 2), -(team.getHeight() / 2), 0f);

            camera.applyToCanvas(canvas);

            camera.restore();

            /* code that has nothing to do with this..(fading) */

            canvas.drawBitmap(team, null, rect, paint);

Rotate3DAnimation is the answer for you. Here is the class

And here is the tutorial too: Tutorial of 3D flip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM