拍摄照片时旋转图像

时间:2019-07-06 23:24:07

标签: android

当我拍摄照片并将它们放在imageview上时,它会旋转。

我正在检查方向,但返回0,我现在不知道如何处理此问题。

在调试的同时,我记录了以下网址,以防万一有人可以提供帮助。

 url = "/storage/emulated/0/3dd5ea68-c9b7-4103-ac01-67ce72bccf8f.png"

逻辑如下:

Bitmap bitmap = BitmapFactory.decodeFile(url);
 try {
    ExifInterface exif = new ExifInterface(url);
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
    Log.d("EXIF", "Exif: " + orientation);
    Matrix matrix = new Matrix();
    if (orientation == 6) {
        matrix.postRotate(90);
    }
    else if (orientation == 3) {
        matrix.postRotate(180);
    }
    else if (orientation == 8) {
        matrix.postRotate(270);
    }
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // rotating bitmap

    mMemoryCache.put(url, rotatedBitmap);
    view.setLocalImageBitmap(rotatedBitmap);

0 个答案:

没有答案
相关问题