private void initImageAngle(){ Bitmap imageBitmap = BitmapFactory.decodeFile(FilePathSession.getFaceImagePath().toString()); Bitmap handlerImage = null; try { Matrix matrix = new Matrix(); ExifInterface exifInterface = new ExifInterface(FilePathSession.getFaceImagePath().toString()); int angle = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); switch (angle){ case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(270, imageBitmap.getWidth(), imageBitmap.getHeight()); handlerImage = Bitmap.createBitmap(imageBitmap, 0, 0, imageBitmap.getWidth(), imageBitmap.getHeight(),matrix,true); mConfirmImage.setImageBitmap(handlerImage); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180, imageBitmap.getWidth(), imageBitmap.getHeight()); handlerImage = Bitmap.createBitmap(imageBitmap, 0, 0, imageBitmap.getWidth(), imageBitmap.getHeight(),matrix,true); mConfirmImage.setImageBitmap(handlerImage); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90, imageBitmap.getWidth(), imageBitmap.getHeight()); handlerImage = Bitmap.createBitmap(imageBitmap, 0, 0, imageBitmap.getWidth(), imageBitmap.getHeight(),matrix,true); mConfirmImage.setImageBitmap(handlerImage); break; default: mConfirmImage.setImageBitmap(imageBitmap); break; } } catch (IOException e) { e.printStackTrace(); } if (handlerImage != null){ try { FileOutputStream fileOutputStream = new FileOutputStream(FilePathSession.getFaceImagePath()); handlerImage.compress(Bitmap.CompressFormat.JPEG, 90 , fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); imageBitmap.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }