Watermark and Screenshot
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:
- A project has been created in the ZEGOCLOUD Console, and valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio and video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
Usage Steps
Watermark
Call the setPublishWatermark interface to set the publishing stream watermark.
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
-
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 } }); -
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
-
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".
-
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.
