Рисование текста поверх растрового изображения в фиксированной позиции - PullRequest
0 голосов
/ 02 июля 2019

Я пытаюсь нарисовать два текста, один на TOP & LEFT из bitmap и другой текст на BOTTOM & LEFT из bitmap, как на картинке ниже:

enter image description here

Приведенный ниже код работает, но положение текста изменяется в зависимости от разрешения экрана. Как я могу исправить это

public Bitmap addVHSEffect(Bitmap bitmap) {
        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);// Text Size
        paint.setTextSize(45.0f);
        paint.setTextAlign(Paint.Align.LEFT);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
        Calendar calendar = Calendar.getInstance();
        canvas.drawBitmap(mutableBitmap, 0, 0, paint);
        canvas.drawText("► REC", 30, 130, paint);
        Paint paint2 = new Paint();
        paint2.setColor(Color.YELLOW);
        paint2.setStrokeWidth(18);
        paint2.setTypeface(plain);
        paint2.setTextSize(40.0f);
        paint2.setTextAlign(Paint.Align.LEFT);
        paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
        canvas.drawBitmap(mutableBitmap, 0, 0, paint2);
        canvas.drawText(getDate(calendar), 30, bitmap.getHeight() - 100, paint2);
        return mutableBitmap;
    }
...