2017-02-17 27 views
1

我在三星設備上的圖像有問題 每次我拍一張照片的垂直形式,但是當它調用圖像庫時,教室 垂直 它用ExifInterface類我無法找到導致imageView中的照片方向與三星手機

我每次拍照我打電話給我的類PreviewImage這是我顯示出圖像 後來我有帶我到指定的個人資料照片我有這個方法的按鈕onActivityResult

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) { 
     try { 
      ExifInterface exifInterface = new ExifInterface(photoFile.getAbsolutePath()); 
      int exif = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 
      switch (exif) { 
       case ExifInterface.ORIENTATION_ROTATE_90: 
        orientation = 90; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_180: 
        orientation = 180; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_270: 
        orientation = 270; 
        break; 
      } 
     } catch (Exception e) { 
      Log.d("tmessages", e.toString()); 
     } 
     Intent intent = new Intent(this, PhotoViewer.class); 
     intent.putExtra(EXTRA_PHOTO_PATH, photoFile.getAbsolutePath()); 
     intent.putExtra(EXTRA_PHOTO_ORIENTATION, orientation); 
     intent.putExtra(EXTRA_PHOTO_EDIT, false); 
     startActivityForResult(intent, 10); 

    } 

這是我PhotoViewer類

private void sendPicture() { 
     Intent returnIntent = new Intent(); 
     returnIntent.putExtra("photoDescription", photoDescription.getText().toString()); 
     returnIntent.putExtra("photoPath", localPath); 
     returnIntent.putExtra("orientation", orientation); 
     setResult(Activity.RESULT_OK, returnIntent); 
     finish(); 
    } 

一旦拍攝完成返回我的個人資料類從那裏它被稱爲

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) { 
     if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) { 
      byte[] photo = AndroidUtilities 
        .createProfileImage(photoFile.getAbsolutePath()); 
      ProfileManager.getInstance().publishPhoto(photo); 
      Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length); 
      avatar.setImageBitmap(decodedByte); 
     }else{ 
      Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show(); 
     } 
    } 

的onActivityResult方法我怎樣才能使形象展示我垂直在個人資料照片?

+0

能否請您使用短語,如「畫像」和而不是「垂直」景觀'。你的問題不清楚。你能否請你審查並改變它,因爲你說你想要垂直顯示圖像,你的評論說它已經顯示垂直。 –

回答

0

你已經完成了一半的工作!只需使用您之前計算的方向:

else if (requestCode == 10 && resultCode == Activity.RESULT_OK) { 
    if (photoFile != null&&LoginController.getInstance().xmppConnection.isConnected()) { 
     byte[] photo = AndroidUtilities 
       .createProfileImage(photoFile.getAbsolutePath()); 
     ProfileManager.getInstance().publishPhoto(photo); 
     Bitmap decodedByte = BitmapFactory.decodeByteArray(photo, 0, photo.length); 
->  decodedByte = rotate(decodedByte, orientation); 
     avatar.setImageBitmap(decodedByte); 
    }else{ 
     Toast.makeText(this,R.string.LabelProfilePhotoFailed, Toast.LENGTH_SHORT).show(); 
    } 
} 

方向 = getIntent()getExtras()getInt(EXTRA_PHOTO_ORIENTATION)。

private static Bitmap rotate(Bitmap bm, int rotation) { 
    if (rotation != 0) { 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(rotation); 
     Bitmap bmOut = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); 
     return bmOut; 
    } 
    return bm; 
} 
+0

你好朋友首先感謝幫助,創建了方法來打開 私人位圖旋轉(位圖decodedByte,int方向)orientation = getIntent()。getExtras()。getInt(EXTRA_PHOTO_ORIENTATION); return decodedByte; } 但是,我沒有得到正確的旋轉,增長,我不斷失敗? – Devix

+0

朋友真的很感謝,還有一個問題呢?如果我拍攝水平照片並且照片保持垂直,在任何時候如何控制?感謝您向我提供垂直照片的方法,而這正是我想要的,但是做一個以橫向模式拍照的測試,我打破了這個圖像,您是否知道這可能是什麼?事先非常感謝你。 – Devix

+0

嘗試添加以下行:getContentResolver()。notifyChange(photoFile,null);在使用ExifInterface之前exifInterface = new ExifInterface(photoFile.getAbsolutePath());如果我的回答對你有幫助,你可以請upvote或接受我的回答:)? –