【问题标题】:How to resize image without loosing image content如何在不丢失图像内容的情况下调整图像大小
【发布时间】:2018-05-20 00:04:46
【问题描述】:

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

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

ThumbnailUtils.extractThumbnail()

这两个选项都会剪切部分图像。所以他们看起来不太好。我只想缩小图片尺寸,不想松散图片内容。

【问题讨论】:

标签: android android-bitmap


【解决方案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;
}

【讨论】:

    【解决方案2】:
        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);
    

    【讨论】:

      【解决方案3】:

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

      https://pngquant.org/

      【讨论】:

      • 他想以编程方式进行
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多