1
我已經實現了一個自定義的相機,我可以從中進行拍照,保存後將其插入媒體存儲並立即顯示。我一直困擾着保存的圖像方向,我試圖直接使用filePath或使用Android圖像內容提供者的方向使用ExifInterface來修復此問題。以人像模式拍照時旋轉的圖像
的方向始終返回0。I已經使用:
Android image selected from gallery Orientation is always 0 : Exif TAG
private int getExifOrientation(String pathName)
{
//for complete info on EXIF orientation visit: http://sylvana.net/jpegcrop/exif_orientation.html
ExifInterface exif=null;
try {
exif = new ExifInterface(pathName);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("ImagePreviewActivity", "Exif data of the image could not be retreived");
}
int orientation=exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
return orientation;
}
private int getRotation(int orientation)
{
int rotation=0;
switch(orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
//orientation values is 6
rotation=90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
//orientation value is 3
rotation=180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
//orientation value is 8
rotation=270;
break;
case -1:
Log.d("ImagePreviewActivity","Error getting orientation from Exif data.");
break;
case 1:
Log.d("ImagePreviewActivity", "Image is properly oriented");
default:
Log.d("ImagePreviewActivity", "The value of orientation is "+orientation);
}
return rotation;
}
private Bitmap rotateBitmap(String pathName,int rotation)
{
Bitmap bmp=BitmapFactory.decodeFile(pathName);
Matrix matrix=new Matrix();
matrix.postRotate(90);
//start from x=0,y=0 and filter=false
Bitmap rotatedBitmap=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,false);
return rotatedBitmap;
}
編輯:
輸出的圖像已被正確顯示,當我拍照的風景模式,但是當以人像模式拍攝照片時,它會返回旋轉的圖像(90度)。 我目前使用基於EXIF的方法。
任何日誌指向我們正確的方向? – njzk2