我想从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();
怎么了?
答案 0 :(得分:1)
您可以将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);
}