我從相機捕獲圖像並將圖像顯示到imageview。它會顯示完美,但在某些設備中自動旋轉90度。我搜索了很多,但無法得到適當的解決方案。請告訴我它的解決方案。提前致謝。如何解決在android中自動旋轉90度的圖像捕捉?
0
A
回答
0
試試這個代碼
public Bitmap adjustImageOrientation(Bitmap image, File f) {
int rotate = 0;
try {
ExifInterface exif = new ExifInterface(f.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_NORMAL:
rotate = 0;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
if (rotate != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
image = Bitmap.createBitmap(image, 0, 0, image.getWidth(),
image.getHeight(), matrix, true);
}
return image;
}
0
使用此方法來確定圖像旋轉。
public int getCameraPhotoOrientation(Uri imageUri, String imagePath) {
int rotate = 0;
try {
_context.getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
}
return rotate;
}
如果該方法不會返回零旋轉圖像。
int degree=getCameraPhotoOrientation(Uri.fromFile(tempFile), fPath);
if (degree!= 0) {
bitmap = tools.rotateOrientationCall(bitmap, degree);
}
旋轉你的位圖。
public Bitmap rotateOrientationCall(Bitmap src, float degree) {
Matrix matrix = new Matrix();
matrix.postRotate(degree);
return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
}
相關問題
- 1. 在Chrome中旋轉90度的圖像
- 2. 在C中旋轉PPM圖像90度
- 3. OpenCV中的圖像旋轉(90度)
- 4. Android發送捕獲的圖像在某些設備中旋轉90度
- 5. 視頻視圖旋轉90度在Android
- 6. 從相機拍攝的iphone圖像自動旋轉-90度
- 7. 順時針旋轉90度的圖像
- 8. matrix.postRotate(90)在圖像旋轉
- 9. 瞭解如何旋轉矩陣90度
- 10. 在Android中一次又一次旋轉圖像90度
- 11. 如何解決在Android上播放時旋轉90度視頻的問題?
- 12. 旋轉90度/ -90度的圖像模糊jquery rotate
- 13. 捕獲的圖片旋轉90度自己
- 14. UIImagePNGRepresentation問題? /圖像旋轉90度
- 15. Kineticjs - 順時針旋轉圖像90度
- 16. 如何旋轉TeeChart 90度
- 17. 如何旋轉StageVideo 90度
- 18. Android - 旋轉Admob視圖90度?
- 19. 如何在Android中捕捉圖像?
- 20. ScrollView/Gallery。捕捉到位。自動旋轉
- 21. 如何捕捉圖像中的Android自動
- 22. 圖片90度旋轉AVCam
- 23. C#旋轉位圖90度
- 24. 地圖旋轉了90度?
- 25. 如何在iOS上將圖像旋轉90度?
- 26. Android相機:如何在指定時間自動捕捉圖像
- 27. 90度圖像旋轉和重置EXIF旋轉
- 28. 如何以C爲增量旋轉90度的bmp圖像?
- 29. 旋轉CALayer 90度?
- 30. 旋轉臺90度
的可能的複製([爲什麼圖像捕捉通過相機獲取的意圖在機器人某些設備旋轉] http://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets - 在Android上旋轉的一些設備) – Dhina
因爲Exif取向與捕獲的相機圖像.. – Meenal