在画布的左上方绘制文本

时间:2019-07-01 20:42:20

标签: java android canvas android-bitmap drawtext

我试图在位图上绘制文本,下面的代码可以工作,但是我没有得到我想要的,例如,如果位图大小发生变化,则文本的位置和TextSize会发生变化:

1080 x 1920:

enter image description here

500 x 500:

enter image description here

    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);

有什么方法可以将文本的大小和位置固定在位图的左上方?

0 个答案:

没有答案