截图模板
本篇文档提供了C/C++ SDK截图模板功能的API调用示例。包含添加截图模板、修改截图模板、删除截图模板、查询截图模板列表。
初始化客户端
使用前请先初始化客户端,请参见初始化。
添加截图模板
调用AddVodTemplate接口,完成添加截图模板功能。
接口参数和返回字段请参见AddVodTemplate。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
* (以下代码示例为雪碧图完整配置)
* @return
*/
Json::Value buildSnapshotTemplateConfig() {
Json::Value templateConfig;
Json::Value snapshotConfig;
snapshotConfig["Count"] = "50";
snapshotConfig["Interval"] = "1";
snapshotConfig["SpecifiedOffsetTime"] = "0";
snapshotConfig["Width"] = "200";
snapshotConfig["Height"] = "200";
snapshotConfig["FrameType"] = "normal";
//雪碧图配置(雪碧图配置必须是建立在普通截图配置之上)
Json::Value spriteSnapshotConfig;
spriteSnapshotConfig["CellWidth"] = "120";
spriteSnapshotConfig["CellHeight"] = "68";
spriteSnapshotConfig["Columns"] = "3";
spriteSnapshotConfig["Lines"] = "10";
spriteSnapshotConfig["Padding"] = "20";
spriteSnapshotConfig["Margin"] = "50";
spriteSnapshotConfig["KeepCellPic"] = "keep";
spriteSnapshotConfig["Color"] = "tomato";
snapshotConfig["SpriteSnapshotConfig"] = spriteSnapshotConfig;
//普通截图配置(与雪碧图原始图配置共用该配置信息)
templateConfig["SnapshotConfig"] = snapshotConfig;
//截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
templateConfig["SnapshotType"] = "SpriteSnapshot";
return templateConfig;
}
/**
* 添加截图模板函数
*/
VodApiResponse addSnapshotVodTemplate(VodCredential authInfo) {
string apiName = "AddVodTemplate";
map<string, string> args;
//模板名称
args["Name"] = "Addtest";
//模板类型,固定值为Snapshot
args["TemplateType"] = "Snapshot";
//截图模板配置数据生成
Json::Value templateConfig = buildSnapshotTemplateConfig();
args["TemplateConfig"] = templateConfig.toStyledString();
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = addSnapshotVodTemplate(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
修改截图模板
调用UpdateVodTemplate接口,完成修改截图模板功能。
接口参数和返回字段请参见UpdateVodTemplate。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
* (以下代码示例为雪碧图完整配置)
* @return
*/
Json::Value buildSnapshotTemplateConfig() {
Json::Value templateConfig;
Json::Value snapshotConfig;
snapshotConfig["Count"] = "50";
snapshotConfig["Interval"] = "1";
snapshotConfig["SpecifiedOffsetTime"] = "0";
snapshotConfig["Width"] = "200";
snapshotConfig["Height"] = "200";
snapshotConfig["FrameType"] = "normal";
//雪碧图配置(雪碧图配置必须是建立在普通截图配置之上)
Json::Value spriteSnapshotConfig;
spriteSnapshotConfig["CellWidth"] = "120";
spriteSnapshotConfig["CellHeight"] = "68";
spriteSnapshotConfig["Columns"] = "3";
spriteSnapshotConfig["Lines"] = "10";
spriteSnapshotConfig["Padding"] = "20";
spriteSnapshotConfig["Margin"] = "50";
spriteSnapshotConfig["KeepCellPic"] = "keep";
spriteSnapshotConfig["Color"] = "tomato";
snapshotConfig["SpriteSnapshotConfig"] = spriteSnapshotConfig;
//普通截图配置(与雪碧图原始图配置共用该配置信息)
templateConfig["SnapshotConfig"] = snapshotConfig;
//截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
templateConfig["SnapshotType"] = "SpriteSnapshot";
return templateConfig;
}
/**
* 修改截图模板函数
*/
VodApiResponse updateSnapshotVodTemplate(VodCredential authInfo) {
string apiName = "UpdateVodTemplate";
map<string, string> args;
//设置要修改的模板ID
args["VodTemplateId"] = "53azf9d796fad9d7b862b2e****";
//模板名称
args["Name"] = "updatetest";
//截图模板配置数据生成
Json::Value templateConfig = buildSnapshotTemplateConfig();
args["TemplateConfig"] = templateConfig.toStyledString();
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = updateSnapshotVodTemplate(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
删除截图模板
调用DeleteVodTemplate接口,完成删除截图模板功能。
接口参数和返回字段请参见DeleteVodTemplate。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 删除截图模板函数
*/
VodApiResponse deleteSnapshotVodTemplate(VodCredential authInfo) {
string apiName = "DeleteVodTemplate";
map<string, string> args;
//设置要删除的模板ID
args["VodTemplateId"] = "53azf9d796fad9d7b862b2e****";
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = deleteSnapshotVodTemplate(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
查询截图模板列表
调用ListVodTemplate接口,完成查询截图模板列表功能。
接口参数和返回字段请参见ListVodTemplate。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 查询截图模板列表函数
*/
VodApiResponse listSnapshotVodTemplate(VodCredential authInfo) {
string apiName = "ListVodTemplate";
map<string, string> args;
//模板类型,固定值为Snapshot
args["TemplateType"] = "Snapshot";
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = listSnapshotVodTemplate(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}
查询截图模板
调用GetVodTemplate接口,完成查询截图模板功能。
接口参数和返回字段请参见GetVodTemplate。调用示例如下:
#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"
/**
* 查询截图模板函数
*/
VodApiResponse getSnapshotVodTemplate(VodCredential authInfo) {
string apiName = "GetVodTemplate";
map<string, string> args;
//设置要查询的模板ID
args["VodTemplateId"] = "53azf9d796fad9d7b862b2e****";
return getAcsResponse(authInfo, apiName, args);
}
// 请求示例
void main() {
VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
VodApiResponse response = getSnapshotVodTemplate(authInfo);
printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}