gpt4 book ai didi

android - 将大图像放入与原始图像质量一样好的小 ImageView 中?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:17 25 4
gpt4 key购买 nike

您好,我正在开发一个很好的 Android 应用程序,我需要将大位图放入小尺寸 imageview。我正在使用大小为 300dp X 300dpimageview 来显示 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com