2013-09-27 10 views
1

사진을 찍은 맞춤형 카메라를 구현하여 미디어 저장소에 삽입하고 바로 표시합니다. 저장된 이미지의 문제로 인해 괴롭혀 왔습니다. 오리엔테이션에서 필자는 직접 FilePath를 사용하여 ExifInterface를 사용하거나 Android 이미지 콘텐츠 제공 업체의 오리엔테이션을 사용하여이 문제를 해결하려고했습니다.사진을 세로 모드로 찍을 때 이미지가 회전합니다.

는 방향이 항상 0.I로 반환됩니다

이미 사용하고 :

Android image selected from gallery Orientation is always 0 : Exif TAG

private int getExifOrientation(String pathName) 
{ 
    //for complete info on EXIF orientation visit: http://sylvana.net/jpegcrop/exif_orientation.html 
    ExifInterface exif=null; 
    try { 
     exif = new ExifInterface(pathName); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     Log.e("ImagePreviewActivity", "Exif data of the image could not be retreived"); 
    } 
    int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); 
    return orientation; 
} 

private int getRotation(int orientation) 
{ 
    int rotation=0; 
    switch(orientation) 
    { 
     case ExifInterface.ORIENTATION_ROTATE_90: 
      //orientation values is 6 
      rotation=90; 
      break; 

     case ExifInterface.ORIENTATION_ROTATE_180: 
      //orientation value is 3 
      rotation=180; 
      break; 

     case ExifInterface.ORIENTATION_ROTATE_270: 
      //orientation value is 8 
      rotation=270; 
      break; 

     case -1: 
      Log.d("ImagePreviewActivity","Error getting orientation from Exif data."); 
      break; 

     case 1: 
      Log.d("ImagePreviewActivity", "Image is properly oriented"); 
      default: 
       Log.d("ImagePreviewActivity", "The value of orientation is "+orientation); 
    } 
    return rotation; 
} 

private Bitmap rotateBitmap(String pathName,int rotation) 
{ 
    Bitmap bmp=BitmapFactory.decodeFile(pathName); 
    Matrix matrix=new Matrix(); 
    matrix.postRotate(90); 
    //start from x=0,y=0 and filter=false 
    Bitmap rotatedBitmap=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,false); 
    return rotatedBitmap; 
} 

편집 : 나는 풍경의 사진을 찍을 때 출력 이미지가 제대로 표시되어

모드이지만 세로 모드에서 사진을 찍을 때 회전 된 이미지 (90도)를 반환합니다. 현재 EXIF ​​기반 방법을 사용하고 있습니다.

+0

정확한 방향을 알려주는 로그가 있습니까? – njzk2

답변

1

전달할 경로 이름의 시작 부분에 "file : //"이 없는지 확인하십시오. ExifInterface는 경로에 접두어가 붙은 경우 오류 또는 기타 문제를 발생시키지 않으며 매번 방향에 대한 기본값을 반환합니다.