Retención de la orientación de la imagen después de la compresión
Aquí está mi código
// // reading an image captured using phone camera. Orientation of this // image is always return value 6 (ORIENTATION_ROTATE_90) no matter if // it is captured in landscape or portrait mode // Bitmap bmp = BitmapFactory.decodeFile(imagePath.getAbsolutePath()); // // save as : I am compressing this image and writing it back. Orientation //of this image always returns value 0 (ORIENTATION_UNDEFINED) imagePath = new File(imagePath.getAbsolutePath().replace(".jpg", "_1.jpg")); FileOutputStream fos0 = new FileOutputStream(imagePath); boolean b = bmp.compress(CompressFormat.JPEG, 10, fos0); fos0.flush(); fos0.close(); fos0 = null;
Después de la compresión y el ahorro, la imagen se gira 90 grados aunque ExifInterface devuelve 0 (ORIENTATION_UNDEFINED). Cualquier puntero, ¿cómo puedo retener la orientación de la imagen de origen; En este caso es 6 (o ORIENTATION_ROTATE_90).
- Guardar imagen en sdcard desde un recurso de drawble en Android
- aplicación es lenta con imágenes en android
- Texto de Android sobre la imagen
- Abrir una imagen mediante URI en el visor de imágenes de galería predeterminado de Android
- Recortar parte particular de la imagen en android
Gracias.
- Acceder a imágenes de la aplicación Fotos en mi aplicación Android
- La falla de carga de AWS S3 encontró una excepción que no se pudo volver a intentar en Android
- ImageView: escala imágenes demasiado grandes hacia abajo, no escala imágenes demasiado pequeñas
- ¿Cómo verificar el desarrollo (digital) de píxeles perfectos en Android?
- OutOfMemoryError al cargar imágenes en RecyclerView
- Insertar contacto (ContactsContract) a través de Intent con imagen (Foto)
- Mostrar imágenesVistas con tema de animación
- ¿Cómo saber si dos imágenes se intersecan mientras una imagen se mueve en android?
Después de poco más de búsqueda en stackoverflow, encontré que alguien ya ha explicado este problema aquí maravillosamente con la solución (que he upvoted).
El siguiente código devolverá Ángulo de imagen por su ORIENTATION
.
public static float rotationForImage(Context context, Uri uri) { if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query( uri, projection, null, null, null); if (c.moveToFirst()) { return c.getInt(0); } } else if (uri.getScheme().equals("file")) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int)exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; } private static float exifOrientationToDegrees(int exifOrientation) { if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { return 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { return 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { return 270; } return 0; } }