2016-07-11 3 views
2

많은 질문이 있지만 문제에 대한 답을 찾지 못했습니다.ExifInterface는 항상 0을 반환합니다. 오리엔테이션

카메라로 캡처하거나 저장소에서로드 할 수있는 프로필 이미지를 표시하려고합니다.

나는 ExifInterface를 사용하여 이미지를로드하는 피카소의 올바른 회전을 결정합니다. 모든 사진에 대한 오리엔테이션이 왜 이해가 안

= 내 코드 아래

0 enter image description here

, 매우 간단 :

private void onCaptureImageResult(Intent data) { 
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); 


    File destination = new File(Environment.getExternalStorageDirectory(), 
      System.currentTimeMillis() + ".jpg"); 

    FileOutputStream fo; 
    try { 
     destination.createNewFile(); 
     fo = new FileOutputStream(destination); 
     fo.write(bytes.toByteArray()); 
     fo.close(); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 


    try { 
     Picasso.with(getBaseContext()).load("file:" + destination.getPath()).rotate(MyTools.getFileExifRotation("file:" + destination.getPath())).into(avatar); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

@SuppressWarnings("deprecation") 
private void onSelectFromGalleryResult(Intent data) { 

    Bitmap bm=null; 
    Uri uri=null; 
    if (data != null) { 
     try { 
      bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData()); 
      uri=data.getData(); 

     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 



    try { 
     Picasso.with(getBaseContext()).load("file:" + uri.getPath()).rotate(MyTools.getFileExifRotation("file:" + uri.getPath())).into(avatar); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 


public static int getFileExifRotation(String path) throws IOException { 
    ExifInterface exifInterface = new ExifInterface(path); 
    int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
    switch (orientation) { 
     case ExifInterface.ORIENTATION_ROTATE_90: 
      return 90; 
     case ExifInterface.ORIENTATION_ROTATE_180: 
      return 180; 
     case ExifInterface.ORIENTATION_ROTATE_270: 
      return 270; 
     default: 
      return 0; 
    } 
} 

나는 LG의 G4 전화를 테스트합니다.

답변

2

당신은 비트 맵을 가지고 있습니다. 비트 맵에는 방향이 포함되지 않습니다. 그런 다음 비트 맵을 .jpg로 압축합니다. 그러면 오리 엔테이션이나 exif 헤더가 추가되지 않습니다.

그래서 .jpg에 ExifInterface를 사용하는 것은 쓸모가 없습니다. 또는 방향을 잡으려고.

당신은 thumbnai를 저장하고 있다는 것을 알고 있습니까? 대신 원본을 사용하십시오.

+0

당신은 바로 내가 내가 직후 EXIF ​​정보를 얻을 수있는 코드를 변경 비트 맵에 근무 :. 개인 무효 onCaptureImageResult (의도 데이터) { 비트 맵 썸네일 = (비트 맵) data.getExtras() 수 ("데이터") ; 시도 { 썸네일 = Tools.rotateImageIfRequired (썸네일, data.getData()); } catch (IOException e) { e.printStackTrace(); } 여전히 작동하지 않습니다. ExifOrientation이 0입니다. 아바타를 표시하려면이 항목이 필요합니다. – WhatsUp

+0

코드를 변경 한 이유가 불분명합니다. 그것은 여전히 ​​비트 맵입니다. 이전과 같은 비트 맵. 비트 맵은 exif 또는 방향 정보를 포함하지 않으므로 모두 의미가 없습니다. 대신 당신이해야 할 일은 이미 말한 것입니다. – greenapps

+0

jpeg 이미지의 exif 정보를 어떻게 얻을 수 있습니까? 즉 이미지를 jpeg로 저장하고 exif 방향 데이터를 보존하는 방법은 무엇입니까? – viper