简体   繁体   English

在动画下旋转位图

[英]Rotating an bitmap under animation

I created an animation along the path from the following code. 我从以下代码沿路径创建了一个动画。

    public void doAnimation(){
        Matrix mxTransform=new Matrix();
        PathMeasure pm=new PathMeasure(path,false);
        float fSegmentLen = (float)((pm.getLength())/50);
        if(iCurStep<=50){
            pm.getMatrix(fSegmentLen * iCurStep, mxTransform,
                    PathMeasure.POSITION_MATRIX_FLAG + PathMeasure.TANGENT_MATRIX_FLAG );
             canvas.drawBitmap(bt, mxTransform, null);
             iCurStep++;
             invalidate();
        }
        else{               
            iCurStep=0;
            animate=0;
            canvas.drawPoint((float)range-10,0f,forPoint);
        }
    }

Now i wanted the bitmap in the code to be rotated while drawing it using the drawBitmap() methos. 现在我希望在使用drawBitmap()方法绘制时旋转代码中的位图。 Thank sin advance. 提前致谢。

For rotate the image, you can use the following code 要旋转图像,可以使用以下代码

public static Bitmap rotate(Bitmap src, float degree) {
    // create new matrix
    Matrix matrix = new Matrix();
    // setup rotation degree
    matrix.postRotate(degree);

    // return new bitmap rotated using matrix
    return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}

if you want more explanation means refer this link http://xjaphx.wordpress.com/2011/06/22/image-processing-rotate-image-on-the-fly/ 如果您需要更多说明,请参考此链接http://xjaphx.wordpress.com/2011/06/22/image-processing-rotate-image-on-the-fly/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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