Reputation: 65
While I load an image from SD to imageview, the image is blur.
To improve image quality... any solution..?
Here is the code...
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);
Upvotes: 0
Views: 514
Reputation: 6201
Image from data return low quality image. Try using a file path and get the image from file path.
here i show to get last image path
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 "";
}
}
So, Same way get full image path to convert bitmap and show it imageview.
Upvotes: 1