Description
When sending images and short videos using the Android/iOS Chat SDK/Chat UI, the SDK has these default behaviors:
- Image thumbnails: The SDK creates a large image at 30% quality from the original, meeting standard size requirements before upload. The longest side after compression won’t exceed 240 px. Thumbnails are used in the chat UI.
- Images: If the original image isn’t selected for sending, the SDK creates a large image at 85% quality from the original, meeting standard size requirements before upload. The longest side after compression won’t exceed 1080 px.
- Short video thumbnails: A thumbnail is generated from the first frame of the short video, using the same method as image thumbnails.
- Short videos: The short video file is compressed to a resolution of 544 * 960.
Your app might need to adjust the SDK’s default compression settings.
Analysis
Modifying the SDK’s default settings isn’t recommended. Potential issues include:
- Increasing thumbnail quality may enlarge the message content. If it exceeds the 128 KB limit, sending may fail.
- Increasing the compression ratio for original images or short videos may result in larger files, increasing upload time and causing slow sending.
Solution
If changes are necessary, test them thoroughly in your development environment.
Android side
Set it during SDK initialization, it is recommended to initialize in Application.onCreate().
val compress = CompressOptions().apply {
imageWidth = 1280 // Max original image width (px)
imageHeight = 1280 // Max original image height(px)
imageQuality = 0.82f // Original image quality (0~1)
maxOriginalImageSize = 300 // Original image size limit (KB)
thumbnailMaxSize = 320 // Max thumbnail edge (px)
thumbnailMinSize = 120 // Min thumbnail edge (px)
thumbnailQuality = 0.35f // Thumbnail quality (0~1)
sightCompressWidth = 720 // Sight compressed width (px)
sightCompressHeight = 1280 // Sight compressed height (px)
}
val params = InitParams(this, "your-app-key").apply {
compressOptions = compress
NCEngine.initialize(params)
iOS side
The following fields map to NCCompressOptions and are applied uniformly when NCEngine.initialize is called. Fields that are not set use the SDK default values.
NCCompressOptions *compress = [[NCCompressOptions alloc] init];
// Original image strategy
compress.imageWidth = @(1280); // Max original image width (px)
compress.imageHeight = @(1280); // Max original image height (px)
compress.imageQuality = @(0.82f); // Original image quality (0~1)
compress.maxOriginalImageSize = @(300); // Original image size limit (KB)
// Thumbnail strategy
compress.thumbnailMaxSize = @(320); // Max thumbnail edge (px)
compress.thumbnailMinSize = @(120); // Min thumbnail edge (px)
compress.thumbnailQuality = @(0.35f); // Thumbnail quality (0~1)
// Short video (Sight) compression resolution
compress.sightCompressWidth = @(720); // Sight compressed width (px)
compress.sightCompressHeight = @(1280); // Sight compressed height (px)
NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"your_app_key"];
params.compressOptions = compress;
[NCEngine initialize:params];