Issue
I want to generate a scaled version of a drawable coming from an imageView and show it as small icon for a dialog. I'm using this code but the picture keeps its initial size
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();
what is wrong ?
Solution
You can take the content of the ImageView as a Bitmap and scale the bitmap itself like this:
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);
}
Answered By - Nicola Gallazzi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.