La foto gira 90 grados mientras captura en algunos teléfonos

La foto está girando 90 grados mientras que la captura de la cámara en samsung resto móvil de otros móviles está trabajando bien. Por favor ayudame para esto.

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, IMAGE_CAPTURE); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try { if (requestCode == IMAGE_CAPTURE) { if (resultCode == RESULT_OK){ Uri contentUri = data.getData(); if(contentUri!=null) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); imageUri = Uri.parse(cursor.getString(column_index)); } tempBitmap = (Bitmap) data.getExtras().get("data"); mainImageView.setImageBitmap(tempBitmap); isCaptureFromCamera = true; } } 

Esto pasa a ser un error en versiones anteriores de Android.

He resuelto este problema sólo obtener el ángulo de orientación y girar el mapa de bits en consecuencia.

 public Bitmap decodeFile(String path) {//you can provide file path here int orientation; try { if (path == null) { return null; } // decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; // Find the correct scale value. It should be the power of 2. final int REQUIRED_SIZE = 70; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 0; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale++; } // decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; Bitmap bm = BitmapFactory.decodeFile(path, o2); Bitmap bitmap = bm; ExifInterface exif = new ExifInterface(path); orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Log.e("ExifInteface .........", "rotation ="+orientation); //exif.setAttribute(ExifInterface.ORIENTATION_ROTATE_90, 90); Log.e("orientation", "" + orientation); Matrix m = new Matrix(); if ((orientation == ExifInterface.ORIENTATION_ROTATE_180)) { m.postRotate(180); //m.postScale((float) bm.getWidth(), (float) bm.getHeight()); // if(m.preRotate(90)){ Log.e("in orientation", "" + orientation); bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), m, true); return bitmap; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { m.postRotate(90); Log.e("in orientation", "" + orientation); bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), m, true); return bitmap; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { m.postRotate(270); Log.e("in orientation", "" + orientation); bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),bm.getHeight(), m, true); return bitmap; } return bitmap; } catch (Exception e) { return null; } } 

También consulte el valor MediaStore.Images.Media.ORIENTATION para obtener el ángulo de rotación. Entonces usted puede girar la imagen por se o lo que.

Lo que estoy haciendo: primero compruebe la orientación de la imagen tomada por la cámara utilizando su información de metadatos, y si encontramos esto en el retrato, entonces tenemos que girar la imagen por 90 y mostrar lo contrario sólo mostrar.

Para obtener la información sobre la orientación de la imagen podemos utilizar ExifInterface. ¡Eso es!

  • Android: LED no se enciende / apaga
  • Tome una foto de html5
  • Cómo agregar efectos de filtrado en tiempo real en la API de la cámara 2 en Android
  • Captura la imagen sin previsualización utilizando la API de la cámara2
  • Android Moto X 4.2.2 Cámara FaceDetectionListener onFaceDetection () nunca llamado
  • Compruebe si el dispositivo tiene una cámara?
  • Importar la Galería de Android
  • Android, cámara frontal y posterior Orientación, Paisaje
  • MediaServer Remote Binder Objeto de cámara muerto - sólo en KITKAT
  • Cámara web externa para cámara a android usando usb
  • Takepicture se bloquea en Android 2.3.3
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.