我需要在我的應用程序中將照片從相機上傳到服務器。它適用於大多數設備。但是有一些設備會導致圖像旋轉90度,這不是我想要的行爲。經過研究,我開始知道它的EXIF數據附有圖像。爲了去除圖像位圖中的EXIF數據,我嘗試了各種各樣的東西,比如重新調整圖像等,但沒有一個爲我工作。任何人都請提出一種方法來執行此任務。如何從安卓相機圖像中刪除EXIF數據
0
A
回答
2
試試這個,
public static Bitmap getImage(Context context, Uri uri)
throws FileNotFoundException, IOException {
InputStream input = context.getContentResolver().openInputStream(uri);
BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
onlyBoundsOptions.inJustDecodeBounds = true;
onlyBoundsOptions.inDither = true;// optional
onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// optional
BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
input.close();
if ((onlyBoundsOptions.outWidth == -1)
|| (onlyBoundsOptions.outHeight == -1))
return null;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inJustDecodeBounds = false;
bitmapOptions.inDither = true;
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// optional
input = context.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
input.close();
ExifInterface ei = new ExifInterface(uri.getPath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
bitmap = rotateImage(bitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
bitmap = rotateImage(bitmap, 180);
break;
}
return bitmap;
}
這裏的URI是從相機拍攝圖像的URI。
對於理解EXIF orienatation:轉到http://www.impulseadventure.com/photo/exif-orientation.html
0
這裏我們使用ExifInterface對象的JPEG文件中讀取標籤和讀取例如圖像的方向屬性
// Variable to store the corrected bitmap.
Bitmap correctedBitMap = null;
ExifInterface exifInterface = new ExifInterface(<PATH OF YOUR PHOTO>);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
現在整數變量取向具有關於信息有多少是由旋轉的圖像,然後將其分別對更改後ExifInterface恆定值&檢查。
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
correctedBitMap = rotateImage(<YOUR BITMAP OBJECT>, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
correctedBitMap = rotateImage(<YOUR BITMAP OBJECT>, 180);
break;
}
下面是rotateImage方法的代碼:
private Bitmap rotateImage(Bitmap source, float angle) {
Bitmap bitmap = null;
Matrix matrix = new Matrix();
matrix.postRotate(angle);
try {
bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
matrix, true);
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return bitmap;
}
相關問題
- 1. 如何從CarrierWave圖像中刪除EXIF(相機)數據?
- 2. 如何從相機文件夾中刪除圖像
- 3. 安卓相機意圖
- 4. 安卓相機意圖
- 5. 我如何刪除安卓
- 6. 如何刪除安卓
- 7. 獲取相機膠捲圖像及其EXIF數據?
- 8. 使用PEL(PHP EXIF庫),有沒有辦法從圖像的EXIF數據中刪除嵌入的縮略圖?
- 9. 安卓圖像上傳到服務器從相機錯誤
- 10. 安卓相機zoom
- 11. Codeigniter strip圖像EXIF數據
- 12. 安卓相機人像方向
- 13. Xamarin安卓從圖庫中獲取圖像數據
- 14. 安卓相機和保存在SD卡中的圖像android
- 15. 如何從圖形中刪除圖像
- 16. 如何計算安卓相機捕獲的圖像中物體的深度
- 17. 安卓相機問題(垂直相機|人像)
- 18. 從Arduino Leonardo玩安卓相機快門
- 19. 如何在保存在相機膠捲上的圖像上添加圖像方向exif元數據信息?
- 20. 使用PHP從JPG中刪除EXIF數據
- 21. 測光相機 - 安卓
- 22. 安卓相機預覽
- 23. 安卓相機的空氣
- 24. 安卓相機控件
- 25. 安卓相機檢測
- 26. 安卓相機翻轉
- 27. 安卓相機信息
- 28. 相機預覽 - 安卓
- 29. 安卓相機AutoFocus on Demand
- 30. 安卓相機菜單
而且哪裏的位圖從何而來? – greenapps 2014-10-20 08:25:25
查看編輯答案 – 2014-10-20 08:27:41
但是你的代碼是做什麼的?總是旋轉?請澄清。 – greenapps 2014-10-20 08:31:55