我通过以下方法将文本转换为位图:
private Bitmap textToBitmap(String text)
{
Bitmap myBitmap = Bitmap.createBitmap(400, 50, Bitmap.Config.ARGB_4444);
Canvas myCanvas = new Canvas(myBitmap);
Paint paint = new Paint();
Typeface clock = Typeface.createFromAsset(context.getAssets(),"fonts/myfont.ttf");
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setTypeface(clock);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE );
paint.setTextSize(38);
paint.setTextAlign(Paint.Align.RIGHT);
myCanvas.drawText(text, 400, 30, paint);
return myBitmap;
}
但是在某些手机中,我的位图很小,而在另一些手机中,我的位图很大 为什么会发生?
答案 0 :(得分:0)
Bitmap myBitmap = Bitmap.createBitmap(400, 50, Bitmap.Config.ARGB_4444);//its unit is px, practical size of 1 px is different in various device.
您应根据设备scaledDensity调整位图的大小,这里是a good solution