android - 在动画下旋转位图

标签 android animation

我使用以下代码沿路径创建了一个动画。

    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);
        }
    }

现在我希望代码中的位图在使用 drawBitmap() 方法绘制时旋转。提前感谢罪过。

最佳答案

要旋转图片,可以使用下面的代码

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);
}

如果您需要更多解释,请引用此链接 http://xjaphx.wordpress.com/2011/06/22/image-processing-rotate-image-on-the-fly/

关于android - 在动画下旋转位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10732994/

相关文章:

android - 在 ListActivity 中添加操作栏

android - 使用 RxAndroid MVP Retrofit 修改回调

android - 无法在 AVD 中创建新设备

java - 无法解析 : com. google.android.gms :play-services-gcm:7. 5.+

javascript - 如何用reactjs实现长滚动和分屏?

java - 设备上的计费服务不可用。 (响应 : 3:Billing Unavailable)

jquery - 使用 jQuery、CSS、HTML5 在表格单元格中进行图片动画对齐

python - 保存 mayavi 动画

react-native - 如何在功能组件中编写Animated.Value.addListener?

javascript - jquery平滑滚动在歌剧中出错