我想生成一个可绘制从ImageView的未来的缩放版本,并显示一个对话框,小图标。我使用这个代码,但画面保持其初始大小
Drawable drw = image.getDrawable().mutate().getConstantState().newDrawable();
Drawable drwScal = new ScaleDrawable(drw, 0, 0.5f, 0.5f).getDrawable();
drwScal.setLevel(5000);
new MaterialDialog.Builder(context)
.title(String.format(getResources().getString(R.string.summary)))
.icon(drwScal)
.content(sommaire)
.forceStacking(true)
.show();
怎么了 ?
你可以采取的ImageView作为位图的内容和缩放位图本身是这样的:
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
Bitmap bitmap = drawable.getBitmap();
private static Bitmap scaleBitmap(Bitmap bitmap, float scaleFactor) {
final int sizeX = Math.round(bitmap.getWidth() * scaleFactor);
final int sizeY = Math.round(bitmap.getHeight() * scaleFactor);
return Bitmap.createScaledBitmap(bitmap, sizeX, sizeY, false);
}