开发者

Rotate the bitmap by degree in Android

i'm developing a shooting game with bow and arrow.. so how to rotate the BOW..?? i tried with different animation classes but it di开发者_开发技巧dnt work...


You can use the Matrix class.
Here is some code you can try:

Matrix matrix = new Matrix();
matrix.setRotate(degrees);
Bitmap bmpBowRotated = Bitmap.createBitmap(bmpBow, 0, 0, bmpBow.getWidth(),getHeight(), matrix, false);


A method for rotate the bitmap

public static Bitmap rotateImage(Bitmap src, float degree) 
{
        // create new matrix
        Matrix matrix = new Matrix();
        // setup rotation degree
        matrix.postRotate(degree);
        Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
        return bmp;
}


Well you can do the rotation manually and go frame-by-frame animation? Simply alter the bitmap that is being drawn each frame. What kinds of animation have you tried so far? I would think this could be done with a RotateAnimation though?


This might help you , rotating and scaling a bitmap image using matrix parameter.

http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜