Android - 圖片旋轉

摘要:Android - 圖片旋轉


import android.graphics.Bitmap;
import android.graphics.Matrix;

public class ImageUtils {
    public static Bitmap rotation(Bitmap picture,int degree) {
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(picture,picture.getWidth(),picture.getHeight(),true);
        Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);        
        return rotatedBitmap;
    } 
}

 

若要將圖片向左旋轉,則輸入-90,向右旋轉則輸入90