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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章