我从画廊拍摄了缩略图,画面尺寸较小,尺寸调整为300 * 300。
通过这样做,图像看起来如此模糊。
从图库中获取图片
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
try {
flag = 1;
Uri selectedImage = imageReturnedIntent.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); // file
// path
// of
// selected
// image
cursor.close();
// Convert file path into bitmap image using below line.
yourSelectedImage = download.getResizedBitmap(
image.decodeImage(filePath),270,228);
// put bitmapimage in your imageview
profile_image.setImageBitmap(
yourSelectedImage);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
图片大小调整
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth)
{
try
{
if(bm!=null)
{
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return resizedBitmap;
}
答案 0 :(得分:2)
放大图像时图像会变得模糊(除非您使用的是矢量图像并且使用的是位图)。除了拉伸图像以适应新尺寸之外,您的getResizedBitmap
方法不会做任何其他事情。解决问题的唯一方法是选择较大的图像(但最终会遇到宽高比问题,所以你应该重新考虑缩放算法)。
答案 1 :(得分:0)
当然,放大位图图像会像素化。