logo
Video Call
On this page

Watermark and Screenshot

2024-02-29

Feature Overview

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

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

Example Source Code Download

Please refer to Download Example Source Code to get the source code.

For related source code, please check the files in the "/ZegoExpressExample/Others/src/main/java/im/zego/others/beautyandwatermarkandsnapshot" directory.

Prerequisites

Before implementing watermark and screenshot features, please ensure:

Usage Steps

Watermark

Call ZegoWatermark to configure an image URL for a watermark and the size and position of the watermark in the picture.

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", ".jpeg".

The imageURL parameter in the ZegoWatermark object supports passing three path formats: absolute path, Assets, and Android URI path.

file://[Absolute path of the image on the Android device]: You need to store the image in a directory of the Android device, for example, the private directory of the Android app: "/sdcard/Android/data/im.zego.zegoexpressapp/ZegoLogo.png".

// Supports JPG and PNG format images. If the image is placed in the assets directory of the Android project, imageURL must use "asset://" as a prefix. If it is an absolute path on the device, imageURL must use "file://" as a prefix + absolute path on the device
String imageURL = "file:///sdcard/Android/data/im.zego.zegoexpressapp/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
Rect layout = new Rect(0,0,300,600);
ZegoWatermark watermark = new ZegoWatermark(imageURL, layout);
// Set watermark, supports dynamic modification during publishing stream
sdk.setPublishWatermark(watermark, true);

asset://[Image resource name]: You need to store the image in the "assets" directory of the Android project.

// Supports JPG and PNG format images. If the image is placed in the assets directory of the Android project, imageURL must use "asset://" as a prefix. If it is an absolute path on the device, imageURL must use "file://" as a prefix + absolute path on the device
String imageURL = "asset://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
Rect layout = new Rect(0,0,300,600);
ZegoWatermark watermark = new ZegoWatermark(imageURL,layout);
// Set watermark, supports dynamic modification during publishing stream
sdk.setPublishWatermark(watermark, true);

The Android URI path format is: String path = "uri://" + uri.toString();

// Must use "uri://" as a prefix
String imageURL = "uri://" + "content://com.android.providers.media.documents/document/image%3A1353";

// 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
Rect layout = new Rect(0,0,300,600);
ZegoWatermark watermark = new ZegoWatermark(imageURL,layout);
// Set watermark, supports dynamic modification during publishing stream
sdk.setPublishWatermark(watermark, true);

Screenshot

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

    engine.takePublishStreamSnapshot(new IZegoPublisherTakeSnapshotCallback() {
        @Override
        public void onPublisherTakeSnapshotResult(int errorCode, Bitmap image) {
            //Save image
        }
    });
  2. After playing stream, call the takePlayStreamSnapshot interface to take a screenshot of the playing stream picture.

    engine.takePlayStreamSnapshot(streamID,new IZegoPlayerTakeSnapshotCallback() {
        @Override
        public void onPlayerTakeSnapshotResult(int errorCode, Bitmap image) {
            //Save image
        }
    });
    }

FAQ

  1. How to specify the imageURL in ZegoWatermark?

    Supports images in JPG and PNG formats. If the image is placed in the "assets" directory folder of the Android project, imageURL must use "asset://" as a prefix. If it is an absolute path on the device, imageURL must use "file://" as a prefix + absolute path on the device.

  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