@ Nullable public static Bitmap readImageFromPath ( String imagePath , int width , int height ) { File imageFile = new File ( imagePath ) ; if ( imageFile . exists ( ) ) { try { BufferedInputStream inputStream = new BufferedInputStream ( new FileInputStream ( imageFile ) ) ; BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeStream ( inputStream , null , options ) ; inputStream . close ( ) ; options . inJustDecodeBounds = false ; options . inSampleSize = computeSampleSize ( options , width , height ) ; Bitmap sampledBitmap = null ; boolean attemptSuccess = false ; while ( ! attemptSuccess ) { inputStream = new BufferedInputStream ( new FileInputStream ( imageFile ) ) ; try { sampledBitmap = BitmapFactory . decodeStream ( inputStream , null , options ) ; attemptSuccess = true ; } catch ( Exception e ) { options . inSampleSize *= 2 ; } inputStream . close ( ) ; } String lowerPath = imagePath . toLowerCase ( ) ; if ( lowerPath . endsWith ( ".jpg" ) || lowerPath . endsWith ( ".jpeg" ) ) { int degrees = computeDegree ( imagePath ) ; if ( degrees > 0 ) { Matrix matrix = new Matrix ( ) ; matrix . setRotate ( degrees ) ; Bitmap newBitmap = Bitmap . createBitmap ( sampledBitmap , 0 , 0 , sampledBitmap . getWidth ( ) , sampledBitmap . getHeight ( ) , matrix , true ) ; if ( newBitmap != sampledBitmap ) { sampledBitmap . recycle ( ) ; sampledBitmap = newBitmap ; } } } return sampledBitmap ; } catch ( Exception ignored ) { } } return null ; }
Deposit in the province read images mViewWidth is high the greater the picture clearer but also the memory .