2012-05-23 4 views
4

갤러리의 이미지를 비트 맵 API를 통해로드하고 있지만 이미지의 방향이 저장된 것과 다릅니다. 어딘가에 stackoverflow에 난 그 oreintation 값을 얻으려면 다음 행렬을 회전 읽을 필요가 읽습니다. 나는 이것을 시도했지만 내 방향은 exif 인터페이스에서 0으로오고있다. 당신이 getAttributeInt에서 다시 0을 받고있는 경우갤러리에서 올바른 방향의 이미지를로드 할 수 없습니다.

 int desiredImageWidth = 310; // pixels 
     int desiredImageHeight = 518; // pixels 

     Log.i("FA", "Image Loading "+strFileName); 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     Bitmap newImage = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(strFileName, o), 
                desiredImageWidth, 
                desiredImageHeight, 
                false); 

     Bitmap finalBmp = getCorrectOrientedBitmap(strFileName,newImage); 

     Bitmap myBitmap32 = finalBmp.copy(Bitmap.Config.ARGB_8888, true); 

     Mat matImg = Utils.bitmapToMat(myBitmap32); 

내 주요 방향 함수는 그냥 이미지가 그 안에 저장된 모든 방향 정보를 가지고 있지 않습니다 "회전"을 의미한다고 생각,

private Bitmap getCorrectOrientedBitmap(String filename,Bitmap Source) throws IOException{ 

    Bitmap rotatedBitmap = null; 
    ExifInterface exif = new ExifInterface(filename); 
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); 

    Matrix matrix = new Matrix(); 
    Log.i("FA", "orientation "+orientation); 
    switch(orientation) 
    { 
    case 6: 
     matrix.postRotate(90); 
     break; 
    case 3: 
     matrix.postRotate(180); 
     break; 
    case 8: 
     matrix.postRotate(270); 
     break; 
    } 
    rotatedBitmap = Bitmap.createBitmap(Source, 0, 0, Source.getWidth(), Source.getHeight(), matrix, true); 

    return rotatedBitmap; 
} 
+0

나는 또한 동일한 문제로 달리고있다. 그러나 제 경우에는 갤러리의 그림 중 일부가 다른 방향으로 나타납니다. 효과가있는 솔루션을 게시 할 수 있습니까? – user2376920

답변

0

입니다 . 온라인 도구를 사용하여 독립적으로 확인하거나 좋은 이미지 뷰어를 다운로드하여 확인할 수 있습니다.

다른 장치에서이 코드를 사용해 보셨습니까? 테스트 장치가 방향 태그를 저장하지 않을 수도 있습니까?

This page에는 수행하려는 작업을 수행하기위한 멋진 샘플 코드가 있습니다. 거기에는 몇 가지 개선점이있을 수 있습니다.

관련 문제