setWatermark method

Future<void> setWatermark(
  1. String assetUrl,
  2. int streamType,
  3. double x,
  4. double y,
  5. double width
)

在指定的位置添加水印

水印位置由 xywidth 参数确定。

  • x:水印的 X 坐标,是 0 到 1 之间的浮点数。
  • y:水印的 Y 坐标,是 0 到 1 之间的浮点数。
  • width:水印的宽度,是 0 到 1 之间的浮点数。
  • height:是不用设置的,SDK 内部会根据水印图片的宽高比自动计算一个合适的高度。

例如,如果当前编码分辨率为 540x960,将 (x, y, width) 设置为 (0.1, 0.1, 0.2),那么水印左上角的坐标将为 (540 * 0.1, 960 * 0.1),即 (54, 96),水印宽度将为 540 * 0.2 = 108 px,高度将自动计算。

参数:

assetUrl 可以是在 Flutter 中定义的资产资源地址,如 'images/watermark_img.png',或者是在线图片地址

streamType 如果屏幕共享通道也需要水印,则需要调用两次 setWatermark。有关详细信息,请参阅 TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG

x 水印位置的统一 X 坐标。取值范围:[0,1]

y 水印位置的统一 Y 坐标。取值范围:[0,1]

width 水印的统一宽度。取值范围:[0,1]

不支持:

  • web
  • Windows

Implementation

Future<void> setWatermark(
    String assetUrl, // Resource address in `assets`
    int streamType,
    double x,
    double y,
    double width) async {
  String imageUrl = assetUrl;
  String type = 'network'; // Online image by default
  if (assetUrl.indexOf('http') != 0) {
    type = 'local';
  }
  return _channel.invokeMethod('setWatermark', {
    "type": type,
    "imageUrl": imageUrl,
    "streamType": streamType,
    "x": x.toString(),
    "y": y.toString(),
    "width": width.toString()
  });
}