gpt4 book ai didi

java - 为什么位图大小在不同的屏幕上会发生变化?

转载 作者:行者123 更新时间:2023-11-29 02:25:42 25 4
gpt4 key购买 nike

我使用这种方法将文本转换为位图:

 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com