
您知道那些給您的聊天帶來興奮的小 GIF 嗎?好吧,我們為您準備了一個很酷的技巧。準備好對他們說你自己的話吧!在這篇博文中,我們將解釋如何使用 C# 編程和 REST API 來實現這一點。即使您不熟悉技術,這也比您想像的要容易。準備好升級你的 GIF 遊戲吧!
步驟大綱:
第 1 步:設置 C# GIF 水印 SDK
首先,確保您的項目中設置了 GroupDocs.Watermark Cloud SDK for .NET。您可以通過 NuGet 包管理器 或使用 .NET CLI 中的後續命令將此 SDK 添加到您的項目中:
dotnet add package GroupDocs.Watermark-Cloud --version 23.4.0
第2步:開始API客戶端的初始化
要設置 API 客戶端,請從 儀表板 獲取您的 客戶端 ID 和 客戶端密鑰,然後插入提供的代碼,如下所示:
//Get clientId & clientSecret from https://dashboard.groupdocs.cloud (free registration is required). | |
string clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; | |
string clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | |
string myStorage = "test-internal-storage"; | |
var configuration = new Configuration(clientId, clientSecret); | |
configuration.ApiBaseUrl = "https://api.groupdocs.cloud"; |
第 3 步:上傳 GIF 圖片
在將水印應用於 GIF 圖像之前,需要上傳要添加水印的 GIF 圖像。您可以通過使用以下任意方法將文件上傳到雲存儲來完成此操作:
- 使用瀏覽器中的上傳文件API一一上傳所有文件。
- 使用儀表板。
- 使用下面給出的代碼示例以編程方式上傳:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// Create necessary API instances var storageApi = new StorageApi(configuration); var fileApi = new FileApi(configuration); var path = @"H:\groupdocs-cloud-data"; var files = Directory.GetFiles(path, "*.gif", SearchOption.AllDirectories); foreach (var file in files) { var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); var response = storageApi.ObjectExists(new ObjectExistsRequest(relativeFilePath, myStorage)); if (response.Exists != null && !response.Exists.Value) { var fileStream = File.Open(file, FileMode.Open); fileApi.UploadFile(new UploadFileRequest(relativeFilePath, fileStream, myStorage)); fileStream.Close(); } }
因此,上傳的文件將在雲上儀表板的文件部分中可用。
步驟 4:使用 C# 在 GIF 上創建疊加文本
以下步驟和示例代碼展示瞭如何使用 GIF 水印 REST API 在 C# 中向 GIF 圖像添加水印。
- 首先:獲取憑據(AppKey 和 AppSID)。
- 下一步:配置 API 並初始化 WatermarkApi。
- 下一步:指定 GIF 文件路徑。
- 下一步:定義水印選項(文本、字體、大小)。
- 下一步:創建請求。
- 最後:使用 API 添加水印。
以下代碼示例演示如何使用 GIF 水印 REST API 在 C# 中向 GIF 圖像插入水印。
string MyAppKey = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud | |
string MyAppSid = ""; // Get AppKey and AppSID from https://dashboard.groupdocs.cloud | |
var configuration = new Configuration(MyAppSid, MyAppKey); | |
var apiInstance = new WatermarkApi(configuration); | |
var fileInfo = new FileInfo | |
{ | |
FilePath = "sample.gif" | |
}; | |
var options = new WatermarkOptions() | |
{ | |
FileInfo = fileInfo, | |
WatermarkDetails = new List<WatermarkDetails> | |
{ | |
new WatermarkDetails | |
{ | |
TextWatermarkOptions = new TextWatermarkOptions | |
{ | |
Text = "Hello World!", | |
FontFamilyName = "Arial", | |
FontSize = 12d, | |
} | |
} | |
} | |
}; | |
var request = new AddRequest(options); | |
var response = apiInstance.Add(request); |
您將在以下屏幕截圖中看到輸出:

第 5 步:下載生成的 GIF 文件
上一步中給出的代碼將生成的文件保存在雲端。要下載它,您可以使用以下代碼片段。
結論
讀完本博文後,您將全面了解如何使用 GroupDocs.Watermark Cloud REST API 及其 C# SDK 將疊加文本集成到 GIF 上。準備好提升您的 GIF 並通過動態且引人入勝的視覺內容吸引您的觀眾。
適用於 .NET 的 GroupDocs.Watermark Cloud SDK 簡化了流程並提供了一系列自定義選擇。我們鼓勵您深入研究文檔,並嘗試不同的配置,在圖像或文檔上製作水印,完全滿足您的品牌需求。
此外,您還會發現 API 參考 部分,可直接從瀏覽器直接可視化並與我們的 API 進行交互。 C# SDK 的完整源代碼可在 Github 上公開訪問。
最終,我們堅持不懈地生成以不同文件格式及其通過 REST API 解析為中心的新穎博客內容。關注最新動態。祝您編碼成功並滿意!
免費在線 GIF 水印應用程序
如需向 GIF 添加疊加文本的免費方法,請嘗試一下在線 GIF 水印應用程序。這個GIF水印工具是使用前面提到的C#水印庫創建的。
問一個問題
如果您對 GIF 水印 有任何疑問或困惑,請隨時通過我們的 論壇 與我們聯繫。
也可以看看
以下是一些可能對您有幫助的相關文章: