2013-01-14 3 views
0

매우 흥미로운 문제를 발견했습니다. 카메라 사진을 찍은 후에 (세로 모드로 장치를 잡고 회전하지 않음) 주어진 사진이 회전하는 경우가 있지만 항상 그런 것은 아닙니다. 일부 장치는 항상 회전 된 사진을 제공하지만 exif 또는 mediastore 정보로 회전 할 수 있습니다. 그러나이 경우 exif와 mediastore는 방향이 0이지만 이미지가 회전한다고합니다. 가장 좌절감이 많은 것은 완전히 무작위 적입니다. 코드는 매우 간단합니다 :안드로이드 카메라 이미지가 임의로 회전했습니다.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, currentFileUri); 
startActivityForResult(intent, RequestCodeCollection.CAMERA_IMAGE_CAPTURE); 

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     try { 
      oldImageExifInterface = new ExifInterface(currentFileUri.getPath()); 
     } 
} 

이 문제를 본 사람이 있습니까? OS 업데이트 후 Galaxy Nexus에서 경험 (4.1.1)

+0

가능한 복제 ([이미지 캡처 사용하여 카메라 의도가 안드로이드에서 일부 장치에 회전됩니다 이유] http://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets -rotated-on-some-devices-in-android) –

+0

여기에 현재 - http://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets-rotated-on-some- devices-in-android –

답변

0

시도해보십시오.

try { 
     File f = new File(imagePath); 
     ExifInterface exif = new ExifInterface(f.getPath()); 
     int orientation = exif.getAttributeInt(
       ExifInterface.TAG_ORIENTATION, 
       ExifInterface.ORIENTATION_NORMAL); 

     int angle = 0; 

     if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { 
      angle = 90; 
     } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { 
      angle = 180; 
     } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { 
      angle = 270; 
     } 

     Matrix mat = new Matrix(); 
     mat.postRotate(angle); 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inSampleSize = 2; 

     Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(f), 
       null, options); 
     bitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), 
       bmp.getHeight(), mat, true); 
     ByteArrayOutputStream outstudentstreamOutputStream = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.PNG, 100, 
       outstudentstreamOutputStream); 
     imageView.setImageBitmap(correctBmp); 

    } catch (IOException e) { 
     Log.w("TAG", "-- Error in setting image"); 
    } catch (OutOfMemoryError oom) { 
     Log.w("TAG", "-- OOM Error in setting image"); 
    } 
관련 문제