生成的ImageView绘制的缩放版本

问题描述 投票:0回答:1

我想生成一个可绘制从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();

怎么了 ?

android drawable android-drawable image-resizing
1个回答
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);
}
© www.soinside.com 2019 - 2024. All rights reserved.