1

写真を撮って保存し、メディアストアに挿入してすぐに表示するカスタムカメラを実装しました。保存された画像の向きの問題に悩まされていました。ExifInterfaceを使用してこれを修正しようとしましたfilePath を直接、または Android 画像コンテンツ プロバイダーからの方向を使用して。

向きは常に 0 として返されます。私はすでに使用しています:

ギャラリーから選択した Android 画像 Orientation は常に 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 ベースの方法を使用しています。

4

1 に答える 1