将图像加载到imageview时的图像模糊

时间:2012-10-20 13:48:52

标签: android

当我将图像从SD加载到imageview时,图像模糊。

提高图像质量...任何解决方案..?

这是代码......

Bitmap image = null;
                try {
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };
                    Cursor cursor = getContentResolver()
                            .query(selectedImage, filePathColumn, null,
                                    null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor
                            .getColumnIndex(filePathColumn[0]);
                    String filePath = cursor.getString(columnIndex);
                    cursor.close();
                    File file = new File(filePath);
                    image = decodeFile(file);

                } catch (java.lang.OutOfMemoryError e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(),
                            "Image size is too large !", Toast.LENGTH_SHORT)
                            .show();
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getApplicationContext(),
                            "Try with different image !",
                            Toast.LENGTH_SHORT).show();
                }
                mainImage = (ImageView) findViewById(R.id.img_mainImg);
                mainImage.setImageBitmap(image);

1 个答案:

答案 0 :(得分:1)

来自数据的图像返回低质量图像。尝试使用文件路径并从文件路径中获取图像。

这里我展示了获取最后一个图像路径

private String getLastImagePath() {
        final String[] imageColumns = { MediaStore.Images.Media._ID,
                MediaStore.Images.Media.DATA };
        final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
        Cursor imageCursor = managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
                null, null, imageOrderBy);
        if (imageCursor.moveToFirst()) {
            int id = imageCursor.getInt(imageCursor
                    .getColumnIndex(MediaStore.Images.Media._ID));
            String fullPath = imageCursor.getString(imageCursor
                    .getColumnIndex(MediaStore.Images.Media.DATA));
            return fullPath;
        } else {
            return "";
        }
    }

所以,同样的方法获得完整的图像路径来转换位图并显示它的imageview。