Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android上的图像重定尺寸_Java_Android_Image_Bitmap - Fatal编程技术网

Java android上的图像重定尺寸

Java android上的图像重定尺寸,java,android,image,bitmap,Java,Android,Image,Bitmap,我有一个功能,可以根据我的应用程序的高度和宽度之间的理想比例调整图像大小问题是图像的质量当我尝试调整图像大小时,它会失去很多质量,它会变得像素化,就像如果在绘画上调整图像大小,有什么方法可以提高质量 理想图像比0744 320x430 这是我的密码 public Bitmap redimensionarImagenMaximo(Bitmap mBitmap, float newWidth, float newHeigth){ //Redimensionamos int

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

理想图像比0744 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);

位图大小是多少?目标尺寸是多少?感谢您的回复完美图像是320x430不同图像的原始尺寸变化功能人们可以达到我的应用如果我只是将过滤器更改为true,没有什么改变它相同的大小/质量,我使用第二个大小增加这么多,我想要一个低的大小有50 kbs的jpg和更好的质量第一行将做双线性插值向下缩放,但最近的邻居向上缩放。您是否试图放大图像以使其质量差?我正在尝试将图像大小调整为320x430它可以有一个边距,以便在手机中显示图像而不失真,并且我也想减小图像的大小,但质量太差