1

アプリの高さと幅の理想的な比率に応じて画像のサイズを変更する機能があります。問題は、画像のサイズを変更しようとすると画像の品質です。サイズを変更すると、多くの品質が失われます。塗装したのですが、品質を上げる方法はありますか?

完全な画像比率 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);
    }
4

1 に答える 1

0

コードの最後の行を次のように置き換えます。

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

true双一次補間の場合、最後のパラメーターを に設定します。

または、単に使用できます

return Bitmap.createScaledBitmap(mBitmap, width, height, true);
于 2013-06-11T17:16:28.533 に答える