java全棧工程師:從java後端到全棧,高級電商全棧系統大課【30周完結】

download:java全棧工程師:從java後端到全棧,高級電商全棧系統大課【30周完結】

 

半年時間,帶你從後端走向全棧
從後端到全棧CTO,我花了10年,這10年濃縮成了120多個小時,個人10年,你或許只須要半年,我但願
你比我幸運,少一些投石問路式的摸索,以更快的速度成爲能勝任更高職位,更受市場青睞的全棧工程師
 
 
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.media.ExifInterface;
 
import java.io.IOException;
 
/**
  * Created by pengkv on 15/12/2.
  * 圖片旋轉工具類
  */
public class ImageRotateUtil {
 
     /**
      * 讀取圖片的旋轉的角度
      *
      * @param path 圖片絕對路徑
      * @return 圖片的旋轉角度
      */
     public static int getBitmapDegree(String path) {
         int degree = 0 ;
         try {
             // 從指定路徑下讀取圖片,並獲取其EXIF信息
             ExifInterface exifInterface = new ExifInterface(path);
             // 獲取圖片的旋轉信息
             int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                     ExifInterface.ORIENTATION_NORMAL);
             switch (orientation) {
                 case ExifInterface.ORIENTATION_ROTATE_90:
                     degree = 90 ;
                     break ;
                 case ExifInterface.ORIENTATION_ROTATE_180:
                     degree = 180 ;
                     break ;
                 case ExifInterface.ORIENTATION_ROTATE_270:
                     degree = 270 ;
                     break ;
             }
         } catch (IOException e) {
             e.printStackTrace();
         }
 
         return degree;
     }
 
     /**
      * 將圖片按照某個角度進行旋轉
      *
      * @param bm     須要旋轉的圖片
      * @param degree 旋轉角度
      * @return 旋轉後的圖片
      */
     public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
         Bitmap returnBm = null ;
 
         // 根據旋轉角度,生成旋轉矩陣
         Matrix matrix = new Matrix();
         matrix.postRotate(degree);
         try {
             // 將原始圖片按照旋轉矩陣進行旋轉,並獲得新的圖片
             returnBm = Bitmap.createBitmap(bm, 0 , 0 , bm.getWidth(), bm.getHeight(), matrix, true );
         } catch (OutOfMemoryError e) {
             e.printStackTrace();
             //當內存溢出時,利用遞歸進行從新旋轉
             while (returnBm == null ) {
                 System.gc();
                 System.runFinalization();
                 returnBm = rotateBitmapByDegree(bm, degree);
             }
         }
         if (returnBm == null ) {
             returnBm = bm;
         }
         if (bm != returnBm) {
             bm.recycle();
         }
         return returnBm;
     }
}
相關文章
相關標籤/搜索