截图模板

本篇文档提供了.NET SDK截图模板功能的API调用示例。包含添加截图模板、修改截图模板、删除截图模板、查询截图模板列表。

初始化客户端

使用前请先初始化客户端,请参见初始化

添加截图模板

调用AddVodTemplate接口,完成添加截图模板功能。

接口参数和返回字段请参见AddVodTemplate。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.AddVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                AddVodTemplateResponse response = AddVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// 添加截图模板函数
        /// </summary>
        /// <returns>The vod template.</returns>
        /// <param name="client">Client.</param>
        public static AddVodTemplateResponse AddVodTemplate(DefaultAcsClient client)
        {
            // 构造请求
            AddVodTemplateRequest request = new AddVodTemplateRequest();
            // 模板名称
            request.Name = "addVodTemplate";
            // 模板类型,固定值为Snapshot
            request.TemplateType = "Snapshot";
            // 截图模板配置数据生成
            request.TemplateConfig = BuildSnapshotTemplateConfig();

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
        /// (以下代码示例为雪碧图完整配置)
        /// </summary>
        /// <returns>截图模板的配置</returns>
        public static string BuildSnapshotTemplateConfig()
        {
            JObject templateConfig = new JObject();
            JObject snapshotConfig = new JObject();
            snapshotConfig.Add("Count", "50");
            snapshotConfig.Add("Interval", "1");
            snapshotConfig.Add("SpecifiedOffsetTime", "0");
            snapshotConfig.Add("Width", "200");
            snapshotConfig.Add("Height", "200");
            // 普通截图配置(与雪碧图原始图配置共用该配置信息)
            templateConfig.Add("SnapshotConfig", snapshotConfig);
            //雪碧图配置(雪碧图配置必须是建立在普通截图配置之上)
            JObject spriteSnapshotConfig = new JObject();
            spriteSnapshotConfig.Add("CellWidth", "120");
            spriteSnapshotConfig.Add("CellHeight", "68");
            spriteSnapshotConfig.Add("Columns", "3");
            spriteSnapshotConfig.Add("Lines", "10");
            spriteSnapshotConfig.Add("Padding", "20");
            spriteSnapshotConfig.Add("Margin", "50");
            spriteSnapshotConfig.Add("KeepCellPic", "keep");
            spriteSnapshotConfig.Add("Color", "tomato");
            snapshotConfig.Add("SpriteSnapshotConfig", spriteSnapshotConfig);

            //截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
            templateConfig.Add("SnapshotType", "SpriteSnapshot");

            return templateConfig.ToString();
        }
    }
}

修改截图模板

调用UpdateVodTemplate接口,完成修改截图模板功能。

接口参数和返回字段请参见UpdateVodTemplate。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.UpdateVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateVodTemplateResponse response = UpdateVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// 修改截图模板函数
        /// </summary>
        /// <returns>UpdateVodTemplateResponse</returns>
        /// <param name="client">Client.</param>
        public static UpdateVodTemplateResponse UpdateVodTemplate(DefaultAcsClient client)
        {
            // 构造请求
            UpdateVodTemplateRequest request = new UpdateVodTemplateRequest();
            request.VodTemplateId = "53azf9d796fad9d7b862b2e****";
            // 模板名称
            request.Name = "new template name";

            // 截图模板配置数据生成
            request.TemplateConfig = BuildSnapshotTemplateConfig();

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// 构建截图模板的配置数据,根据具体设置需求修改对应的参数值
        /// (以下代码示例为普通截图完整配置)
        /// </summary>
        /// <returns>截图模板的配置</returns>
        public static string BuildSnapshotTemplateConfig()
        {
            JObject templateConfig = new JObject();
            JObject snapshotConfig = new JObject();
            snapshotConfig.Add("Count", "50");
            snapshotConfig.Add("Interval", "1");
            snapshotConfig.Add("SpecifiedOffsetTime", "0");
            snapshotConfig.Add("Width", "200");
            snapshotConfig.Add("Height", "200");
            // 普通截图配置(与雪碧图原始图配置共用该配置信息)
            templateConfig.Add("SnapshotConfig", snapshotConfig);

            //截图类型(存在雪碧图配置,该类型必须是"SpriteSnapshot",否则为"NormalSnapshot")
            templateConfig.Add("SnapshotType", "SpriteSnapshot");

            return templateConfig.ToString();
        }
    }
}

删除截图模板

调用DeleteVodTemplate接口,完成删除截图模板功能。

接口参数和返回字段请参见DeleteVodTemplate。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteVodTemplateResponse response = DeleteVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Deletes the vod template.
        /// </summary>
        /// <returns>The vod template.</returns>
        /// <param name="client">Client.</param>
        public static DeleteVodTemplateResponse DeleteVodTemplate(DefaultAcsClient client)
        {
            // 构造请求
            DeleteVodTemplateRequest request = new DeleteVodTemplateRequest();
            //设置要删除的模板ID
            request.VodTemplateId = "53azf9d796fad9d7b862b2e****";

            return client.GetAcsResponse(request);
        }
    }
}

查询截图模板列表

调用ListVodTemplate接口,完成查询截图模板列表功能。

接口参数和返回字段请参见ListVodTemplate。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.ListVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                ListVodTemplateResponse response = ListVodTemplate(client);

                if (response.VodTemplateInfoList != null && response.VodTemplateInfoList.Count > 0) 
                {
                    foreach (ListVodTemplateResponse.ListVodTemplate_VodTemplateInfo templateInfo in response.VodTemplateInfoList) 
                    {
                        // 模板ID
                        Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
                        // 模板名称 
                        Console.WriteLine("Name = " + templateInfo.Name);
                    }
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Lists the vod template.
        /// </summary>
        /// <returns>The vod template.</returns>
        /// <param name="client">Client.</param>
        public static ListVodTemplateResponse ListVodTemplate(DefaultAcsClient client)
        {
            // 构造请求
            ListVodTemplateRequest request = new ListVodTemplateRequest();
            //模板类型,固定值为Snapshot
            request.TemplateType = "Snapshot";

            return client.GetAcsResponse(request);
        }
    }
}

查询截图模板

调用GetVodTemplate接口,完成查询截图模板功能。

接口参数和返回字段请参见GetVodTemplate。调用示例如下:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// 主函数
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetVodTemplateResponse response = GetVodTemplate(client);
                if (response.VodTemplateInfo != null)
                {
                    // 模板ID
                    Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
                    // 模板名称 
                    Console.WriteLine("Name = " + templateInfo.Name);
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId != null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Gets the vod template.
        /// </summary>
        /// <returns>The vod template.</returns>
        /// <param name="client">Client.</param>
        public static GetVodTemplateResponse GetVodTemplate(DefaultAcsClient client)
        {
            // 构造请求
            GetVodTemplateRequest request = new GetVodTemplateRequest();
            // 设置要查询的模板ID
            request.VodTemplateId = "53azf9d796fad9d7b862b2e****";

            return client.GetAcsResponse(request);
        }
    }
}