5

ビットマップ API を介してギャラリーから画像を読み込んでいますが、画像の向きが保存したものとは異なります。スタックオーバーフローのどこかで、方向値を取得してからマトリックスを回転させる必要があることを読みました。私はこれを試しましたが、私の向きはexifインターフェースから0として来ています。

        int desiredImageWidth = 310;  // pixels
        int desiredImageHeight = 518; // pixels

        Log.i("FA", "Image Loading "+strFileName);
        BitmapFactory.Options o = new BitmapFactory.Options();
        Bitmap newImage = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(strFileName, o), 
                                                   desiredImageWidth, 
                                                   desiredImageHeight, 
                                                   false);

        Bitmap finalBmp = getCorrectOrientedBitmap(strFileName,newImage);

        Bitmap myBitmap32 = finalBmp.copy(Bitmap.Config.ARGB_8888, true);

        Mat matImg = Utils.bitmapToMat(myBitmap32);

私の主なオリエンテーション機能は

    private Bitmap getCorrectOrientedBitmap(String filename,Bitmap Source) throws IOException{

    Bitmap rotatedBitmap = null;
    ExifInterface exif = new ExifInterface(filename);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

    Matrix matrix = new Matrix();
    Log.i("FA", "orientation "+orientation);
    switch(orientation)
    {
    case 6:
        matrix.postRotate(90);
        break;
    case 3:
        matrix.postRotate(180);
        break;
    case 8:
        matrix.postRotate(270);
        break;
    }
    rotatedBitmap = Bitmap.createBitmap(Source, 0, 0, Source.getWidth(), Source.getHeight(), matrix, true);

    return rotatedBitmap;
}
4

1 に答える 1

0

0から戻ってきた場合getAttributeIntは、「回転した」画像に方向情報が保存されていないことを意味していると思います。オンライン ツールで個別に再確認するか、優れた画像ビューアーをダウンロードして確認することができます。

このコードを別のデバイスで試しましたか? テスト デバイスが方向タグを保存しない可能性はありますか?

このページには、あなたがやろうとしていることを実行するための素敵なサンプル コードがいくつかあります。

于 2012-05-23T19:11:30.997 に答える