我使用这种方法将文本转换为位图:
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;
}
但在某些手机中,我的位图非常小,而在其他手机中,它非常大 为什么会这样?
最佳答案
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
关于java - 为什么位图大小在不同的屏幕上会发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52379464/