Android Guardar imagen Exif Información goes Wrong in Marshmallow 6.0.1
En mi cámara personalizada, necesito guardar la orientación de una imagen capturada. Este código funciona perfectamente para otras versiones de Android. Pero no funciona en 6.0.1. El resultado que obtengo es incorrecto después de guardar los atributos en el archivo de imagen.
try { exif = new ExifInterface(pictureFile.getAbsolutePath()); exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + orientation); exif.saveAttributes(); } catch (IOException e) { e.printStackTrace(); }
- Habilitar la rotación de la pantalla android
- Cómo controla la orientación de la pantalla del dispositivo Android
- Sólo en la aplicación Android
- Android: configuración forzosa restablecida en los cambios de orientación
- La parte delantera y trasera del androide captó la cuestión de la orientación de la imagen, giró de manera incorrecta
- ¿Por qué `android: screenOrientation =" detrás "` no hay efecto en android 4.1.2?
- ¿Cuáles son los pros y los contras de usar configChanges = "orientación" para dispositivos Android?
- ¿Cómo tratar con dispositivos Android que no respetan los datos de orientación EXIF?
- Viewflipper Receptor no registró error mientras cambio de orientación en 2.1 y 2.2
- Cómo configurar la orientación de la cámara Android correctamente?
- Android onConfigurationChanged no se llama
- Rotación inexplicable de la cámara Android en la captura de algunos dispositivos (no en EXIF)
- Forzar el modo de orientación "retrato"
Pruebe esto para guardar la orientación de los diferentes ángulos de las imágenes capturadas: –
Options options = new Options(); // downsizing image as it throws OutOfMemory Exception for larger // images options.inSampleSize = 8; ExifInterface exif; try { exif = new ExifInterface(fileUri.getPath()); int orientation = exif.getAttributeInt( ExifInterface.TAG_ORIENTATION, 0); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 3) { matrix.postRotate(180); Log.d("EXIF", "Exif: " + orientation); } else if (orientation == 8) { matrix.postRotate(270); Log.d("EXIF", "Exif: " + orientation); } myBitmap = BitmapFactory.decodeFile(path_img, options); myBitmap = Bitmap.createBitmap(myBitmap, 0, 0, myBitmap.getWidth(), myBitmap.getHeight(), matrix, true); } catch (Exception e) { }
Las otras soluciones están reescribiendo la imagen en lugar de manipular la información EXIF. Yo sugeriría hacerlo como lo intentó con las constantes correctas:
try { exif = new ExifInterface(pictureFile.getAbsolutePath()); exif.setAttribute(ExifInterface.TAG_ORIENTATION, Integer.toString(ExifInterface.ORIENTATION_ROTATE_90)); exif.saveAttributes(); } catch (IOException e) { e.printStackTrace(); }
Basado en el código fuente necesitas usar uno de estos valores:
-
ExifInterface.ORIENTATION_UNDEFINED
-
ExifInterface.ORIENTATION_NORMAL
-
ExifInterface.ORIENTATION_FLIP_HORIZONTAL
-
ExifInterface.ORIENTATION_ROTATE_180
-
ExifInterface.ORIENTATION_FLIP_VERTICAL
-
ExifInterface.ORIENTATION_TRANSPOSE
-
ExifInterface.ORIENTATION_ROTATE_90
-
ExifInterface.ORIENTATION_TRANSVERSE
-
ExifInterface.ORIENTATION_ROTATE_270
Puesto que he experimentado problemas y el comportamiento diferente que leía la información de EXIF de diverso fabricante sugeriría que usted consiga la orientación de la imagen ahorrada URI, después usted podría ahorrarla a la interfaz de EXIF.
public static void getImageOrientationFromUri(@NonNull ContentResolver contentResolver, @NonNull Uri uri) { if (uri.getPath() == null) throw new NullPointerException("URI Path should not be null"); float rotationInDegrees = 0; Cursor cursor = contentResolver.query(uri, new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null); if (cursor != null && cursor.moveToFirst()) { int col = cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION); if (col != -1) rotationInDegrees = cursor.getInt(col); cursor.close(); } // here you can save to the EXIF interface getting the apropriate value from rotationInDegrees //If you want to display the image create the bitmap using: //Bitmap sourceBitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri); //Matrix matrix = new Matrix(); //matrix.preRotate(rotationInDegrees); //you can change the signature of the method to return a `Bitmap` and return //Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, false); }
ACTUALIZACIÓN DE LA BIBLIOTECA DE APOYO:
Google lanzó ayer la versión 25.1.0 de la biblioteca de soporte con una actualización masiva en el ExifInterface que se centra principalmente en la lectura y escritura de los atributos de un archivo de imagen en la última versión android. Por favor, eche un vistazo a la fuente de código y más comprensión de esta actualización.
Espero que esto te ayude
- ¿Posee un adaptador de sincronización para Android?
- Visual Studio 2015 se bloquea al crear / abrir un proyecto Cordova