【发布时间】:2018-05-20 00:04:46
【问题描述】:
我想将图像调整为较小的图像,例如缩略图。我使用了以下选项
Bitmap imageBitmap = Bitmap.createScaledBitmap(mBitmap, 200, 700, false);
和
ThumbnailUtils.extractThumbnail()
这两个选项都会剪切部分图像。所以他们看起来不太好。我只想缩小图片尺寸,不想松散图片内容。
【问题讨论】:
我想将图像调整为较小的图像,例如缩略图。我使用了以下选项
Bitmap imageBitmap = Bitmap.createScaledBitmap(mBitmap, 200, 700, false);
和
ThumbnailUtils.extractThumbnail()
这两个选项都会剪切部分图像。所以他们看起来不太好。我只想缩小图片尺寸,不想松散图片内容。
【问题讨论】:
你必须这样尝试
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;
}
【讨论】:
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);
【讨论】:
如果您想在不损失质量的情况下调整图像大小并且图像来自 drawable/mipmap,那么您应该尝试 pngquant。
【讨论】: