desc:解决水印右边有一条白线的问题

main
xiaowusky 2 years ago
parent 65978e5c68
commit 767781e47f

@ -68,9 +68,9 @@ public class TxtOverlay {
lastTipUpdateTime = currentTimeMillis;
mTip = txt;
// 文字转bitmap
bmp = YUVUtils.generateBitmap(dateFormat.format(lastTipUpdateTime) + "@" + txt, 30, Color.WHITE);
bmp = YUVUtils.generateBitmap(dateFormat.format(lastTipUpdateTime) + "@" + txt, 16, Color.WHITE);
// 缩放旋转bitmap
bmp = YUVUtils.scaleImage(bmp, bmp.getWidth() / 2, bmp.getHeight() / 2, cameraRotationOffset);
bmp = YUVUtils.rotateImage(bmp, cameraRotationOffset);
//转YUV
mark = YUVUtils.getYUVByBitmap(bmp);
}

@ -28,6 +28,23 @@ public class YUVUtils {
return newbm;
}
public static Bitmap rotateImage(Bitmap bm, int cameraRotationOffset) {
if (bm == null) {
return null;
}
int width = bm.getWidth();
int height = bm.getHeight();
Matrix matrix = new Matrix();
matrix.postRotate(360 - cameraRotationOffset);
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
true);
if (bm != null & !bm.isRecycled()) {
bm.recycle();
bm = null;
}
return newbm;
}
//图片转YUV
public static byte[] getYUVByBitmap(Bitmap bitmap) {
if (bitmap == null) {
@ -90,6 +107,9 @@ public class YUVUtils {
width = Math.max(width, (int) Math.ceil(textPaint.measureText(split[i])));
}
int height = lineHeight * split.length;
// 宽高向上取偶数
width = (width + 1) / 2 * 2;
height = (height + 1) / 2 * 2;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
for (int i = 0; i < split.length; i++) {
@ -98,6 +118,9 @@ public class YUVUtils {
} else {
int width = (int) Math.ceil(textPaint.measureText(text));
int height = lineHeight;
// 宽高向上取偶数
width = (width + 1) / 2 * 2;
height = (height + 1) / 2 * 2;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawText(text, 0, Math.abs(fontMetrics.ascent), textPaint);

Loading…
Cancel
Save