您的位置:首页 > 移动开发 > Android开发

android 相片显示歪斜解决办法

2015-09-18 14:34 435 查看
//获得正常图片 

private String picPath;//图片路径

public static Bitmap rotateImage(Bitmap src, getExif(picPath) {

        Matrix matrix = new Matrix();

        matrix.postRotate(degree);

        src = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, 

true);

        return src;

    }

//获得图片角度

private int getExif(final String path) {

        ExifInterface exif;

        int degree = 0;

        try {

            exif = new ExifInterface(path);

        } catch (IOException e) {

            e.printStackTrace();

            exif = null;

        }

        if (exif != null) {

            // 读取图片中相机方向信息

            int ori = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,

                    ExifInterface.ORIENTATION_UNDEFINED);

            // 计算旋转角度

            switch (ori) {

                case ExifInterface.ORIENTATION_ROTATE_90:

                    degree = 90;

                    break;

                case ExifInterface.ORIENTATION_ROTATE_180:

                    degree = 180;

                    break;

                case ExifInterface.ORIENTATION_ROTATE_270:

                    degree = 270;

                    break;

                default:

                    degree = 0;

                    break;

            }

        }

        return degree;

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: