Android 生成可绘制的ImageView的缩放版本

Android 生成可绘制的ImageView的缩放版本,android,drawable,android-drawable,image-resizing,Android,Drawable,Android Drawable,Image Resizing,我想从imageView中生成一个缩放版本的绘图,并将其显示为对话框的小图标。 我正在使用此代码,但图片保持其初始大小 Drawable drw = image.getDrawable().mutate().getConstantState().newDrawable(); Drawable drwScal = new ScaleDrawable(drw, 0, 0.5f, 0.5f).getDrawable();

我想从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=drawable.getBitmap();
专用静态位图缩放位图(位图位图、浮点缩放因子){
final int sizeX=Math.round(bitmap.getWidth()*scaleFactor);
final int sizeY=Math.round(bitmap.getHeight()*scaleFactor);
返回位图.createScaledBitmap(位图、sizeX、sizeY、false);
}