我需要在我的應用程序中將照片從相機上傳到服務器。它適用於大多數設備。但是有一些設備會導致圖像旋轉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. 從Java中的圖像中刪除Exif數據?
- 3. 安卓相機設置圖像
- 4. 安卓相機圖像壓縮
- 5. 從圖片回調閱讀安卓JPEG EXIF元數據
- 6. 刪除圖像按鈕填充(安卓)
- 7. 如何從相機文件夾中刪除圖像
- 8. 從安卓相機的NV21格式中提取黑白圖像
- 9. 從圖像中剝離EXIF數據
- 10. 安卓相機意圖
- 11. 安卓相機意圖
- 12. 如何刪除安卓
- 13. 我如何刪除安卓
- 14. 安卓相機意圖,並從相機得到圖片
- 15. 獲取相機膠捲圖像及其EXIF數據?
- 16. 從callLog刪除 - 安卓2.3.3
- 17. 使用PEL(PHP EXIF庫),有沒有辦法從圖像的EXIF數據中刪除嵌入的縮略圖?
- 18. 編輯/刪除Windows Phone上的Exif圖像數據
- 19. 操縱圖像,而不刪除它的EXIF數據
- 20. 將圖像從安卓相機上傳到網絡服務器
- 21. 安卓圖像上傳到服務器從相機錯誤
- 22. 在Python中刪除EXIF數據?
- 23. 安卓相機setPreviewSize
- 24. 安卓相機zoom
- 25. 安卓相機frezes
- 26. 安卓相機中斷
- 27. Codeigniter strip圖像EXIF數據
- 28. 如何刪除此函數中的exif數據?
- 29. 安卓相機人像方向
- 30. Xamarin安卓從圖庫中獲取圖像數據
而且哪裏的位圖從何而來? – greenapps 2014-10-20 08:25:25
查看編輯答案 – 2014-10-20 08:27:41
但是你的代碼是做什麼的?總是旋轉?請澄清。 – greenapps 2014-10-20 08:31:55