关于从相册取出图片后,图片不能按原来角度显示的问题解决方案

(在F:\java\心情秀)

1、取得图片本身的角度
/**
     * 获得图片的角度进行修正
     */
    private int readPicDegree(String path){
        int degree = 0;
        try {
            ExifInterface exifInterface = new ExifInterface(path);
            int orientation = exifInterface.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION, 
                    ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
            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:
                break;
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        Log.i(TAG, "ct test------------------>degree "+degree);
        return degree;
    }

相关链接:http://blog.csdn.net/liuhanhan512/article/details/8277637

2、获得计算好的insamples的图片

private Bitmap getSrcPic(String path){
        BitmapFactory.Options options = new BitmapFactory.Options();  
        options.inJustDecodeBounds = true;  
        BitmapFactory.decodeFile(path, options);
        
        bitWidth = options.outWidth;  
        bitheight = options.outHeight;
        
        while ((bitWidth / sampleSize > DEFAULT_WIDTH * 2) || (bitheight / sampleSize > DEFAULT_HEIGHT * 2)) {  
            sampleSize *= 2;  
        }
        options.inJustDecodeBounds = false; 
        options.inSampleSize = sampleSize;  
        Bitmap bitmap = BitmapFactory.decodeFile(path, options);
        return bitmap;
    }

相关链接:http://www.cnblogs.com/hellope/archive/2011/08/23/2150400.html

3、对图片进行旋转

private Bitmap rotateBitmap(int angle , Bitmap bitmap){
        Matrix matrix = new Matrix();
        matrix.postRotate(angle);
        //创建新图片
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,  
                bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        return resizedBitmap;
        
    }
原文地址:https://www.cnblogs.com/ct732003684/p/3026608.html