您好,我正在开发一个很好的 Android 应用程序,我需要将大位图放入小尺寸 imageview
。我正在使用大小为 300dp X 300dp 的 imageview
来显示 1024 X 780
如何将大图变小并保持原图的质量?
最佳答案
试试这个:
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
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
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
易于使用:
Bitmap bmResized=getResizedBitmap(yourBitmap,newHeight,newWidth);
然后你得到调整大小的图像
注意:如果你想调整资源图像的大小,使用它来转换为位图:
Bitmap bmOrginal=BitmapFactory.decodeResource(this.getResources(), R.drawble.yourRes);
Bitmap bmResized=getResizedBitmap(bmOrginal,newHeight,newWidth);
然后设置调整大小的图像:
image.setImageBitmap(bmResized);
关于android - 将大图像放入与原始图像质量一样好的小 ImageView 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12804127/