setWatermark method

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

Adds a watermark to the specified location

The watermark position is determined by the x, y, and width parameters.

  • x: X coordinate of watermark, which is a floating point number between 0 and 1.
  • y: Y coordinate of watermark, which is a floating point number between 0 and 1.
  • width: width of watermark, which is a floating point number between 0 and 1.
  • height: it does not need to be set. The SDK will automatically calculate it according to the watermark image's aspect ratio.

For example, if the current encoding resolution is 540x960 and (x, y, width) is set to (0.1, 0.1, 0.2), then the coordinates of the top-left point of the watermark will be (540 * 0.1, 960 * 0.1), i.e., (54, 96), the watermark width will be 540 * 0.2 = 108 px, and the height will be calculated automatically.

Parameters:

assetUrl can be an asset resource address defined in Flutter such as 'images/watermark_img.png' or an online image address

streamType setWatermark needs to be called twice if the screen sharing channel also requires a watermark. For more information, please see TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG

x Unified X coordinate of the watermark position. Value range: [0,1]

y Unified Y coordinate of the watermark position. Value range: [0,1]

width Unified width of the watermark. Value range: [0,1]

Platform not supported:

  • 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 _cloudChannel!.invokeMethod('setWatermark', {
    "type": type,
    "imageUrl": imageUrl,
    "streamType": streamType,
    "x": x.toString(),
    "y": y.toString(),
    "width": width.toString()
  });
}