android短视频开发,上传视频自动添加水印实现的相关代码
private static Bitmap createWatermark(Bitmap bitmap, String mark) {
int fontsize = DensityUtil.dp2px(25);
int height = DensityUtil.dp2px(35);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
Paint p = new Paint();
// 水印颜色
//p.setColor(Color.parseColor("#c5576370"));
p.setColor(Color.WHITE);
// 水印字体大小
p.setTextSize(fontsize);
//抗锯齿
p.setAntiAlias(true);
//绘制图像
canvas.drawBitmap(bitmap, 0, 0, p);
//绘制文字
String[] marks = mark.split("#");
int k = 0;
for (int i = 0; i < marks.length; i++) {
String text = marks[i];
int x = 10;
int y = bitmap.getHeight() / 2 + i * height + k * height;
if (marks[i].length() > 25) {//超过一行;
canvas.drawText(text.substring(0, 24), x, y, p);
canvas.drawText(text.substring(24), x, y + height, p);
k++;
} else {
canvas.drawText(text, x, y, p);
}
}
// canvas.save(Canvas.ALL_SAVE_FLAG); mengshirui
canvas.save();
canvas.restore();
return bmp;
}
以上就是android短视频开发,上传视频自动添加水印实现的相关代码, 更多内容欢迎关注之后的文章