3 回答

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
好的,大家好,這個(gè)錯(cuò)誤似乎不會(huì)在一段時(shí)間內(nèi)得到修復(fù)。盡管我找到了一種實(shí)現(xiàn)ExifInformation的方法,以便使兩個(gè)設(shè)備(具有正確的Exif標(biāo)簽和不正確的exif標(biāo)簽的設(shè)備一起使用)。
因此,問(wèn)題出在某些(較新的)設(shè)備上,存在一個(gè)錯(cuò)誤,該錯(cuò)誤使拍攝的照片沒(méi)有適當(dāng)?shù)膃xif標(biāo)簽就被保存在您的應(yīng)用文件夾中,而正確旋轉(zhuǎn)的圖像被保存在android默認(rèn)文件夾中(即使不應(yīng)該)。 。
現(xiàn)在我要做的是,我記錄從應(yīng)用程序啟動(dòng)相機(jī)應(yīng)用程序的時(shí)間。關(guān)于活動(dòng)結(jié)果,我查詢媒體提供者以查看是否保存了此時(shí)間戳后是否保存了任何圖片。這意味著,最有可能的操作系統(tǒng)將正確旋轉(zhuǎn)的圖片保存在默認(rèn)文件夾中,并且當(dāng)然在媒體存儲(chǔ)中放置了一個(gè)條目,我們可以使用此行中的旋轉(zhuǎn)信息?,F(xiàn)在,確保我們正在查看正確的圖像,我將該文件的大小與我可以訪問(wèn)的文件大小進(jìn)行比較(保存在我自己的應(yīng)用程序文件夾中);
int rotation =-1;
long fileSize = new File(filePath).length();
Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE }, MediaStore.MediaColumns.DATE_ADDED + ">=?", new String[]{String.valueOf(captureTime/1000 - 1)}, MediaStore.MediaColumns.DATE_ADDED + " desc");
if (mediaCursor != null && captureTime != 0 && mediaCursor.getCount() !=0 ) {
while(mediaCursor.moveToNext()){
long size = mediaCursor.getLong(1);
//Extra check to make sure that we are getting the orientation from the proper file
if(size == fileSize){
rotation = mediaCursor.getInt(0);
break;
}
}
}
現(xiàn)在,如果此時(shí)的旋轉(zhuǎn)度仍為-1,則意味著這是具有正確旋轉(zhuǎn)信息的手機(jī)之一。此時(shí),我們可以對(duì)返回到onActivityResult的文件使用常規(guī)exif方向
else if(rotation == -1){
rotation = getExifOrientationAttribute(filePath);
}
您可以輕松地找出如何找到EXIF方向想在這個(gè)問(wèn)題的答案在Android相機(jī)定位問(wèn)題
還要注意,只有在Api 5級(jí)之后才支持ExifInterface。因此,如果您想在2.0之前支持電話,則可以使用我為Drew Noakes提供的Java便利庫(kù)。http://www.drewnoakes.com/code/exif/
祝您的圖片旋轉(zhuǎn)愉快!
編輯:因?yàn)橛腥藛?wèn),我用過(guò)的意圖以及我的開始方式是這樣的
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//mediaFile is where the image will be saved
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mediaFile));
startActivityForResult(intent, 1);

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊
您也可以這樣:
Matrix matrix = new Matrix();
// rotate the Bitmap (there a problem with exif so we'll query the mediaStore for orientation
Cursor cursor = getApplicationContext().getContentResolver().query(selectedImage,
new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor.getCount() == 1) {
cursor.moveToFirst();
int orientation = cursor.getInt(0);
matrix.preRotate(orientation);
}
- 3 回答
- 0 關(guān)注
- 1185 瀏覽
添加回答
舉報(bào)