水印(动态水印)
1、水印Bitmap和路径设置 SDK支持图片水印的路径配置,以及直接设置Bitmap对象的方式。 1.1水印路径设置
有两种方式设置:
方式一: 指定sdcard目录下的文件,需要指定前缀file://, 例如mLogoPath = "file:///sdcard/test.png";
方式二: 指定assets目录下面的文件,需要指定前缀assets://,例如mLogoPath = "assets://test.png";
2、图片水印设置方式 通过Streamer的接口showWaterMarkLogo和hideWaterMarkLogo来显示和隐藏水印 接口说明
/**
* 设置并显示logo水印
*
* @param path logo图片文件的路径
* @param x logo的显示位置,0-1之间,相对于视频
* @param y logo的显示位置,0-1之间,相对于视频
* @param w logo的显示宽度,0-1之间,相对于视频,为0时会根据h及logo图片的比例自适应
* @param h logo的显示高度,0-1之间,相对于视频,为0时会根据w及logo图片的比例自适应
* @param alpha logo的透明度,0-1之间
*/
void showWaterMarkLogo(String path, float x, float y, float w, float h, float alpha);
/**
* 隐藏logo水印
*/
void hideWaterMarkLogo();
3、时间水印设置方式 通过Streamer的接口showWaterMarkTime和hideWaterMarkTime来显示和隐藏时间水印
接口说明:
/**
* 在推流视频中显示时间水印
*
* @param x 时间戳的显示位置,0-1之间,相对于视频
* @param y 时间戳的显示位置,0-1之间,相对于视频
* @param w 时间戳的显示宽度,0-1之间,相对于视频,高度会自适应
* @param color 时间戳的颜色
* @param alpha 时间戳的显示透明度,0-1之间
*/
void showWaterMarkTime(float x, float y, float w, int color, float alpha);
/**
* 隐藏推流视频中的时间水印
*/
void hideWaterMarkTime();
4、动态水印的支持 demo 从2017-9-20后加入了支持动态水印的示例代码,可以支持gif、webp格式的动态图片水印 在Demo中,第二次开启水印即可看到动态水印效果
注意:软编兼容模式下,不支持动态水印。
Demo中的 AnimatedImageCapture 类使用fresco库的pipeline方法,将动图解码后转化为texture输出。 使用时,将该采集模块的输出端连接到预览和编码mixer的空闲index上,然后开始解码即可。
代码使用示例如下:
初始化
// 在Application的onCreate中初始化Fresco库
Fresco.initialize(this);
// 创建AnimatedImageCapture
mAnimatedImageCapture = new AnimatedImageCapture(this, mStreamer);
开启动态水印,参数设置方法与图片水印相同
// show animated watermark logo, support gif/webp, not valid in SOFTWARE_COMPAT mode
private void showAnimatedWaterMark(String url, float x, float y, float w, float h, float a) {
// 连接到空闲的预览、编码mixer上
cnImgTexSrcPin.connect(mStreamer.getImgTexPreviewMixer().getSinkPin(3));
cnImgTexSrcPin.connect(mStreamer.getImgTexMixer().getSinkPin(3));
// 配置水印显示位置及大小
mStreamer.getImgTexPreviewMixer().setRenderRect(3, x, y, w, h, a);
mStreamer.getImgTexMixer().setRenderRect(3, x, y, w, h, a);
// 开始显示
start(context, url);
}
关闭动态水印
private void hideAnimatedWaterMark() {
stop();
cnImgTexSrcPin.disconnect(false);
}