我有这种方法,我在图像上绘制一些文本:
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);
}
这就是我调用此方法的方式:
lineIconView.setImageDrawable(writeOnDrawable(R.drawable.icon_line_numbre, linea.getNumero()));
这个 ImageView ( lineIconView
) 已经有R.drawable.icon_line_numbre
资源集。如果我不调用该writeOnDrawable
函数,则图像会以其原始大小显示,但在调用它之后,图像的大小会大大减小。
这是正常行为吗?