2

我有像这样旋转图像的代码

private void rotate(Bitmap src, float degree) {


        // create new matrix     
        Matrix matrix = new Matrix();
        // setup rotation degree
        matrix.postRotate(degree);
        // return new bitmap rotated using matrix
        Bitmap ro = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);

        mImageView.setImageBitmap(ro);
        recycleBitmap();
    }

它可以旋转,但是如果我连续单击旋转按钮,我的图像不可见,如何解决这个问题?谢谢

4

2 回答 2

0

尝试在 postRotate 之前设置 postScale

 // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    // rotate the Bitmap
    matrix.postRotate(45);
于 2012-11-16T10:05:46.340 回答
0

您在代码中所做的是每次单击旋转按钮时都会更改矩阵值。连续更改值可能会破坏图像的结构。您可以调整或缩放矩阵。试试这个'

private void rotate(Bitmap src, float degree) {
        // create new matrix     
        Matrix matrix = new Matrix();

 matrix.postRotate(degree,px,py);//(px,py)is pivot point with reference to which the image is rotated
        // return new bitmap rotated using matrix
        Bitmap ro = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);

        mImageView.setImageBitmap(ro);
        recycleBitmap();
    }
于 2012-11-16T10:26:08.700 回答