logo
Video Call
On this page

Watermark and Screenshot

2024-02-29

Introduction

When you need to set copyright owner logos for educational teaching courseware and other scenarios, you can use the SDK's watermark feature.

This article mainly describes how to use the SDK to implement watermark and screenshot features.

Sample Source Code Download

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

For related source code, please check the "/ZegoExpressExample/Examples/Others/Beautify" file.

Prerequisites

Before implementing watermark and screenshot features, please ensure:

Usage Steps

Watermark

Call ZegoWatermark to configure a watermark image URL and the watermark's size and position in the visuals.

Call the setPublishWatermark interface to set the publishing watermark.

Warning

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

The imageURL parameter in the ZegoWatermark object supports passing two path formats.

file://[Absolute path of image in Bundle]: You need to store the image in any location in the project Bundle, obtain the absolute path of the image through the pathForResource:ofType: method of NSBundle, and add the "file://" prefix.

ZegoWatermark *watermark = [[ZegoWatermark alloc] init];

NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ZegoLogo" ofType:@"png"];
watermark.imageURL = [NSString stringWithFormat:@"file://%@", imagePath];
// The watermark layout takes the upper left corner as 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 = CGRectMake(0, 0, 200, 200);
// Set watermark, supports dynamic modification before and after publishing stream
[self.engine setPublishWatermark:watermark isPreviewVisible:YES];

asset://[Image resource name]: You need to store the image in the "Assets.xcassets" that comes with the iOS project.

ZegoWatermark *watermark = [[ZegoWatermark alloc] init];
watermark.imageURL = @"asset://ZegoLogo";
// The watermark layout takes the upper left corner as 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 = CGRectMake(0, 0, 200, 200);
// Set watermark, supports dynamic modification before and after publishing stream
[self.engine setPublishWatermark:watermark isPreviewVisible:YES];

Screenshot

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

    [[ZegoExpressEngine sharedEngine] takePublishStreamSnapshot:^(int errorCode, ZGImage * _Nullable image) {
    
        if (errorCode == ZegoErrorCodeCommonSuccess && image) {
            NSImageView *imageView =  [[NSImageView alloc]initWithFrame:CGRectMake(0, 0, NSScreen.mainScreen.frame.size.width/2,  NSScreen.mainScreen.frame.size.height/2)];
            imageView.image = image;
            imageView.imageScaling = NSImageScaleAxesIndependently;
        }
    }];
  2. After playing stream, call the takePlayStreamSnapshot interface to take a screenshot of the playing stream visuals.

    [[ZegoExpressEngine sharedEngine] takePlayStreamSnapshot:self.streamID callback:^(int errorCode, ZGImage * _Nullable image) {
        if (errorCode == ZegoErrorCodeCommonSuccess && image) {
            NSImageView *imageView =  [[NSImageView alloc]initWithFrame:CGRectMake(0, 0, NSScreen.mainScreen.frame.size.width/2,  NSScreen.mainScreen.frame.size.height/2)];
            imageView.image = image;
            imageView.imageScaling = NSImageScaleAxesIndependently;
        }
    }];

FAQ

  1. How to specify the layout in ZegoWatermark?

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

Previous

Screen Sharing

Next

Set Video Encoding Mode

On this page

Back to top