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

main
xiaowusky 2 years ago
parent 65978e5c68
commit 767781e47f

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

@ -28,6 +28,23 @@ public class YUVUtils {
return newbm; 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 //图片转YUV
public static byte[] getYUVByBitmap(Bitmap bitmap) { public static byte[] getYUVByBitmap(Bitmap bitmap) {
if (bitmap == null) { if (bitmap == null) {
@ -90,6 +107,9 @@ public class YUVUtils {
width = Math.max(width, (int) Math.ceil(textPaint.measureText(split[i]))); width = Math.max(width, (int) Math.ceil(textPaint.measureText(split[i])));
} }
int height = lineHeight * split.length; int height = lineHeight * split.length;
// 宽高向上取偶数
width = (width + 1) / 2 * 2;
height = (height + 1) / 2 * 2;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
for (int i = 0; i < split.length; i++) { for (int i = 0; i < split.length; i++) {
@ -98,6 +118,9 @@ public class YUVUtils {
} else { } else {
int width = (int) Math.ceil(textPaint.measureText(text)); int width = (int) Math.ceil(textPaint.measureText(text));
int height = lineHeight; int height = lineHeight;
// 宽高向上取偶数
width = (width + 1) / 2 * 2;
height = (height + 1) / 2 * 2;
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
canvas.drawText(text, 0, Math.abs(fontMetrics.ascent), textPaint); canvas.drawText(text, 0, Math.abs(fontMetrics.ascent), textPaint);

Loading…
Cancel
Save