ZEGOCLOUD's SDKs provide the ability to watermark your video stream. For example, businesses and organizations can use the watermark feature to display their logo on the video.
This document mainly describes how to implement the watermark and screenshot features with the Video Call SDK.
Before implementing the watermark and screenshot features, make sure you complete the following steps:
Images in "JPG" and "PNG" formats (i.e., image files with subfixes ".jpg", ".jpeg", and ".png") can be used as watermarks.
Currently, the imageURL
parameter in the ZegoWatermark
object supports the following two path formats:
Accessing the image in the Bundle via the absolute path
file://[the absolute path of the image in the bundle]
: If the image is stored somewhere in the Bundle, you obtain the absolute path of the image in the bundle through the pathForResource:ofType:
method of NSBundle
. The imageURL
should start with a prefix file://
followed by the absolute path of the image in the bundle.
```objc
ZegoWatermark *watermark = [[ZegoWatermark alloc] init];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ZegoLogo" ofType:@"png"];
watermark.imageURL = [NSString stringWithFormat:@"file://%@", imagePath];
watermark.layout = CGRectMake(0, 0, 200, 200);
[self.engine setPublishWatermark:watermark isPreviewVisible:YES];
```
Accessing the image in the Assets directory of the iOS project
asset://[image file name]
: The image is must be stored in Assets.xcassets
of the iOS project.
```objc
ZegoWatermark *watermark = [[ZegoWatermark alloc] init];
watermark.imageURL = @"asset://ZegoLogo";
watermark.layout = CGRectMake(0, 0, 200, 200);
[self.engine setPublishWatermark:watermark isPreviewVisible:YES];
```
takePublishStreamSnapshot
method.[[ZegoExpressEngine sharedEngine] takePublishStreamSnapshot:^(int errorCode, UIImage * _Nullable image) {
if (errorCode == ZegoErrorCodeCommonSuccess && image) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width / 2, UIScreen.mainScreen.bounds.size.height / 2)];
imageView.image = image;
imageView.contentMode = UIViewContentModeScaleAspectFit;
}
}];
takePlayStreamSnapshot
method.[[ZegoExpressEngine sharedEngine] takePlayStreamSnapshot:self.streamID callback:^(int errorCode, ZGImage * _Nullable image) {
if (errorCode == ZegoErrorCodeCommonSuccess && image) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width / 2, UIScreen.mainScreen.bounds.size.height / 2)];
imageView.image = image;
imageView.contentMode = UIViewContentModeScaleAspectFit;
}
}];
How to set the layout
property of the ZegoWatermark
object?
The watermark area cannot exceed the size set by the encoding resolution of the stream.
For more details about the encoding resolution of the stream, refer to the setVideoConfig
method.