Android - 保证图片以高为标准,做宽高比同比例拉伸
/**
* 保证图片以高为标准,做宽高比同比例拉伸
*/
private void handleImageView() {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
decodeResource(getContext().getResources(), R.mipmap.preview_bg_window, options);
}
private Bitmap decodeResource(Resources resources, int id, BitmapFactory.Options opts) {
TypedValue value = new TypedValue();
resources.openRawResource(id, value);
opts.inTargetDensity = value.density;
return BitmapFactory.decodeResource(resources, id, opts);
}