То, что вы могли бы сделать, это (извините за версию Java, у меня нет kotlin версии :)):
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, bounds);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = calculateInSampleSize(bounds, reqWidth, reqHeight);
Bitmap bm = BitmapFactory.decodeFile(imagePath, opts);
, где
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
int inSampleSize = 1;
if (reqWidth != 0 & reqHeight != 0) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight
&& (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}
}
return inSampleSize;
}
Что происходит: вы декодируете данные файла, затем, передавая reqwidth / reqheight, уменьшаете его. Затем вы можете передать его в свой макет:)