我试图在位图上绘制文本,下面的代码可以工作,但是我没有得到我想要的,例如,如果位图大小发生变化,则文本的位置和TextSize会发生变化:
1080 x 1920:
500 x 500:
Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
Typeface plain = Typeface.createFromAsset(getAssets(), "VCR.ttf");
Paint paint = new Paint();
paint.setColor(Color.RED); // Text Color
paint.setStrokeWidth(18);
paint.setTypeface(plain);
paint.setTextSize(40);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
Date currentTime = Calendar.getInstance().getTime();
canvas.drawBitmap(mutableBitmap, 0, 0, paint);
canvas.drawText("► REC", 60, 160, paint);
有什么方法可以将文本的大小和位置固定在位图的左上方?