Change this line:
Drawable drawable = (Drawable)new BitmapDrawable(bitmap);
To:
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
Please note that the constructor is BitmapDrawable(Bitmap bitmap)deprecated ( source ), and using the above call seems to guarantee that it will be set correctly with the correct density target.
source
share