一些图像在上传时旋转90度?安卓

时间:2015-10-05 11:23:35

标签: android image bitmap uiimageorientation

将此图像上传到服务器时

。它旋转90度。 这是图像的链接:

https://drive.google.com/file/d/0Bw8vnOWKrLfgWElsRW81SmxXeDA/view?usp=sharing

这是检查方向的代码。但它没有发现激情:

 /**
     * get image matrix rotation by uri
     */
    private static Matrix matrixUriImgRotation(Uri uri) {
        Log.i("imageRotatin", "image rotation called");

        ExifInterface exif = null;
        try {
            exif = new ExifInterface(uri.getPath());
        } catch (Exception e) {
            Log.i("imageRotatin", "exception:" + e.getMessage());
        }

        //get image rotation
        int exifRotation = 0;
        if (exif != null) {
            exifRotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            Log.i("imageRotatin", "exif not null");
        }

        //convert exif rotation to degrees
        int rotationInDegrees = 0;
        if (exifRotation == ExifInterface.ORIENTATION_ROTATE_90) {
            rotationInDegrees = 90;
        } else if (exifRotation == ExifInterface.ORIENTATION_ROTATE_180) {
            rotationInDegrees = 180;
        } else if (exifRotation == ExifInterface.ORIENTATION_ROTATE_270) {
            rotationInDegrees = 270;
        }

        //build matrix
        Matrix matrix = new Matrix();
        if (exifRotation != 0) {
            Log.i("imageRotatin", "rotationInDegree:" + rotationInDegrees);
            matrix.preRotate(rotationInDegrees);
        }

        return matrix;

    }

注意:其他图片上传没有问题。

0 个答案:

没有答案