logo
Video Call
On this page

Watermark and Screenshot

2024-02-29

Introduction

When it is necessary to set copyright owner logos and other scenarios for educational teaching courseware, the watermark function of the SDK can be used.

This document mainly describes how to use the SDK to implement watermark and screenshot functions.

Download Sample Source Code

Please refer to Download Sample Source Code to obtain the source code.

For related source code, please check the files in the "/ZegoExpressExample/Examples/CommonFeatures/WatermarkSnapshot" directory.

Prerequisites

Before implementing watermark and screenshot functions, ensure that:

Usage Steps

Watermark

Call the setPublishWatermark interface to set the publishing stream watermark.

Warning

Watermark images only support two image formats: "PNG" and "JPEG", that is, image files with three suffixes: ".png", ".jpg", and ".jpeg".

The imageURL parameter in the ZegoWatermark object currently only supports "local file transfer protocol", that is, the form of file:///+absolute path.

ZegoWatermark watermark;
watermark.imageURL = "file:///D:/ZegoLogo.png";
// The upper left corner of the watermark layout is the origin of the coordinate system, and the area cannot exceed the size of the encoding resolution setting. If empty, it means canceling the watermark
watermark.layout = ZegoRect(0, 0, 200, 200);
// Set watermark, supports dynamic modification during publishing stream
engine->setPublishWatermark(&watermark, true);

Screenshot

  1. After publishing stream, call the takePublishStreamSnapshot interface to take a screenshot of the publishing stream screen.

    engine->takePublishStreamSnapshot([=](int errorCode, void* snapshot){
        if(errorCode == 0){
            // Save as image
        }
    });
  2. After playing stream, call the takePlayStreamSnapshot interface to take a screenshot of the playing stream screen.

    engine->takePlayStreamSnapshot("streamID", [=](int errorCode, void* snapshot){
        if(errorCode == 0){
            // Save as image
        }
    });

FAQ

  1. How to specify the imageURL in ZegoWatermark?

    "imageURL" currently only supports "local file transfer protocol", that is, the form of "file:///+absolute path".

    For example: "file:///D:/ZegoLogo.png".

  2. How to specify the "layout" in ZegoWatermark?

    The layout of the watermark cannot exceed the currently set video encoding resolution of the publishing stream. For setting the publishing stream encoding resolution, please refer to the setVideoConfig interface.

Previous

Screen Sharing

Next

Set Video Encoding Method

On this page

Back to top