如何在不丢失图像内容的情况下调整图像大小

时间:2017-12-06 07:05:10

标签: android android-bitmap

我想将图片调整为较小的图像,如缩略图。我使用了以下选项

EditMode  = EditOnEnter

Bitmap imageBitmap = Bitmap.createScaledBitmap(mBitmap, 200, 700, false);

这两个选项都会削减部分图像。所以他们看起来不太好。我只想减少图像尺寸,不想丢失图像内容。

3 个答案:

答案 0 :(得分:1)

你必须尝试这样

public 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;
}

答案 1 :(得分:1)

    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    Bitmap bitmap = BitmapFactory.decodeFile(filepath,bmOptions);

   //Part 1 :withcompression Sacle image 200 pixels x 700 pixels this size you can customize as per your requirement

   Bitmap withCompressed = Bitmap.createScaledBitmap(bitmap,200,700,true);

答案 2 :(得分:0)

如果你想在不损失质量的情况下调整图像大小,而图像来自drawable / mipmap,那么你应该尝试pngquant。

https://pngquant.org/