我正在尝试绘制两种文本,一种在bitmap
的 TOP&LEFT 上,另一种在bitmap
的 BOTTOM&LEFT 上如下图所示:
下面的代码有效,但是文本的位置根据屏幕分辨率,如何固定它而改变
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;
}