Java 位图.解码资源调整图像大小

Java 位图.解码资源调整图像大小,java,android,bitmap,Java,Android,Bitmap,我有一种方法,在图像上绘制一些文本: public BitmapDrawable writeOnDrawable(int drawableId, String text){ Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId); Typeface mFace = Typeface.createFromAsset(this.getAssets(),"fonts/progbot.t

我有一种方法,在图像上绘制一些文本:

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()));
此图像视图(
lineIconView
)已具有
R.drawable.icon\u line\u numbre
资源集。如果我不调用
writeOnDrawable
函数,那么图像将以其原始大小显示,但调用后图像的大小会大大减小


这是正常行为吗?

结果表明我对BitmapDrawable使用了错误的构造函数

官方文件对此问题作了如下说明:

BitmapDrawable(位图)此构造函数已弃用。使用 BitmapDrawable(参考资料,位图),以确保可绘制的 正确设置其目标密度

所以我最终使用了:

return new BitmapDrawable(bm);