2017-08-09 95 views
1

在某些設備(Nexus 9,Nexus S,...)上,相機會在ImageView中加載旋轉的圖片。我試圖用ExifInterface修復,但沒有成功。有人有這個代碼示例的想法嗎?捕捉某些Android設備上的相機圖片旋轉

編譯SDK版本是25
分鐘SDK版本是15

public void capturePhoto(String targetFilename) { 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) { 
     startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); 
    } 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == REQUEST_IMAGE_CAPTURE) { 
     Bundle extras = data.getExtras(); 
     Bitmap imageBitmap = (Bitmap) extras.get("data"); 
     mImageView.setImageBitmap(imageBitmap); 
    } 
} 
} 
+1

我遇到了同樣的問題,很久以前,一些設備(三星和聯想)出現了方向問題,其中代碼在其他設備上運行良好,我所做的就是使用[Glide](https:// github。 com/bumptech/glide),將圖像放置在圖像視圖上,甚至嘗試過使用picasso和通用圖像加載器,但不知怎的,Glide工作了 – Sanoop

+0

試試這個:https://stackoverflow.com/a/8914291 – TOho

+2

參考https:// stackoverflow .COM /問題/ 14066038 /爲什麼此結果的圖像捕捉,利用攝像頭意圖 - 獲得旋轉的 - 上一些的設備上,一個 –

回答

0

使用下面的代碼:從這裏設備的

@Override 
    public void onPictureTaken(byte[] data, Camera camera) { 
int rotation = getPhotoRotation(); 
     rotatePicture(rotation, data); 
     savePicture(); 
     setSafeToTakePhoto(true); 
    } 

GET旋轉:以上

private int getPhotoRotation() { 
     int rotation; 
     int orientation = mOrientationListener.getRememberedNormalOrientation(); 
     CameraInfo info = new CameraInfo(); 
     Camera.getCameraInfo(mCameraID, info); 

     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { 
      rotation = (info.orientation - orientation + 360) % 360; 
     } else { 
      rotation = (info.orientation + orientation) % 360; 
     } 

     return rotation; 
    } 
    private int getRememberedNormalOrientation() { 
      rememberOrientation(); 
      return mRememberedNormalOrientation; 
     } 
    private void rememberOrientation() { 
      mRememberedNormalOrientation = mCurrentNormalizedOrientation; 
     } 

使用代碼來檢測移動方向並保存圖像設備旋轉,如果你不想識別移動旋轉set int orientation =你的旋轉;

相關問題