Se l'immagine (foto) è stata scattata da un programma creato dall'utente, è necessario impostare Parameters.setRotation con il valore di rotazione corretto.
Questo, a seconda dell'unità telecamera, ruota l'immagine prima di salvare o salvare il valore di rotazione su exag TAG_ORIENTATION.
Pertanto, se TAG_ORIENTATION è nullo o zero, l'immagine sono nell'orientamento corretto, altrimenti si deve ruotare l'immagine secondo il valore in TAG_ORIENTATION.
CODICE
Get orientamento da EXIF:
ExifInterface exif = null;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
e.printStackTrace();
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
Get bitmap ruotato:
Bitmap bmRotated = rotateBitmap(bitmap, orientation);
Metodo per ruotare bitmap:
public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) {
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_NORMAL:
return bitmap;
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
matrix.setScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.setRotate(180);
break;
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
matrix.setRotate(180);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_TRANSPOSE:
matrix.setRotate(90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.setRotate(90);
break;
case ExifInterface.ORIENTATION_TRANSVERSE:
matrix.setRotate(-90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.setRotate(-90);
break;
default:
return bitmap;
}
try {
Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap.recycle();
return bmRotated;
}
catch (OutOfMemoryError e) {
e.printStackTrace();
return null;
}
}
ho la risposta. http://stackoverflow.com/questions/29971319/image-orientation-android/32747566#32747566 –
Ecco una grande soluzione di una linea mi sono imbattuto in questo:> https://stackoverflow.com/a/34241250/8033090 E ' può richiedere un secondo per caricare, ma ho appena messo del testo dietro la vista dell'immagine che dice "Caricamento immagine" e quando l'immagine viene caricata copre il testo. –