I have this method where I paint some text over an image:
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
Typeface mFace = Typeface.createFromAsset(this.getAssets(),"fonts/progbot.ttf");
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.RED);
paint.setTypeface(mFace);
paint.setTextSize(30);
Canvas canvas = new Canvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
This is how I call this method:
lineIconView.setImageDrawable(writeOnDrawable(R.drawable.icon_line_numbre, linea.getNumero()));
This ImageView (lineIconView) already has the R.drawable.icon_line_numbre resource set. If I don’t call the writeOnDrawable function then the image is shown in its original size, but after calling it the image gets heavily reduced in size.
Is this normal behavior?
Turns out I was using the wrong constructor for BitmapDrawable.
The official documentation says the following on this matter:
So I ended up using: