从ImageView Android中的Sdcard显示时,图像变得模糊

时间:2016-03-28 04:50:47

标签: android imageview landscape

我正在使用此代码,在图像视图中显示来自Sdcard的图像(在横向模式下)。但是Image失去了它的质量而且模糊了。

tl

ImageView xml文件:

progress

1 个答案:

答案 0 :(得分:0)

试试这个,因为即使我遇到同样的问题,你也可以跳过方向部分

        Bitmap bitmap;
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;
        options.inDither = false;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        // down sizing image as it throws OutOfMemory Exception for larger
        // images
        //options.inSampleSize = 16;

        bitmap = BitmapFactory.decodeFile(filePath, options);
        int orientation = getExifOrientation(filePath);


        //rotate bitmap
        Matrix matrix = new Matrix();
        matrix.postRotate(orientation);
        //create new rotated bitmap
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        ivProfile.setImageBitmap(bitmap);

    } catch (Exception e) {
        e.printStackTrace();
    }

public static int getExifOrientation(String filepath) {
    int degree = 0;
    ExifInterface exif = null;
    try {
        exif = new ExifInterface(filepath);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (exif != null) {
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
        if (orientation != -1) {
            // We only recognise a subset of orientation tag values.
            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;
            }

        }
    }

    return degree;
}

快乐编码