gpt4 book ai didi

java - Android 上的重新尺寸图像

转载 作者:行者123 更新时间:2023-12-01 04:38:00 25 4
gpt4 key购买 nike

我有一个功能,可以根据我的应用程序的高度和宽度之间的理想比例调整图像大小,问题是图像的质量,当我尝试调整图像大小时,它会损失很多质量,就像像素化一样如果你在油漆上调整它的大小,有什么方法可以提高质量吗?

完美图像比例 0,744 (320x430)这是我的代码

public Bitmap redimensionarImagenMaximo(Bitmap mBitmap, float newWidth, float newHeigth){
//Redimensionamos
int width = mBitmap.getWidth();
int height = mBitmap.getHeight();
float actual = (float)width/height;
double perfect = 0.7441;
float scaleWidth;
float scaleHeight;
if(perfect >= actual)
{
scaleHeight = ((float) newHeigth) / height;
scaleWidth = scaleHeight;

}
else if(perfect <= actual)
{
scaleWidth = ((float) newWidth) / width;
scaleHeight = scaleWidth;
}
else
{
scaleWidth = newWidth;
scaleHeight = newHeigth;
}
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
return Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, false);
}

最佳答案

替换最后一行代码如何:

return Bitmap.createBitmap(mBitmap, 0, 0, width, height, matrix, true);

将最后一个参数设置为true以进行双线性插值。

或者您可以简单地使用

return Bitmap.createScaledBitmap(mBitmap, width, height, true);

关于java - Android 上的重新尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17046295/

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