The TIFF(標籤圖像檔案格式) is widely used in publishing, graphic design, and photography because of its ability to store high-quality raster graphics. Unlike JPEG or PNG, a TIFF file can hold multiple images or frames within a single file. These multi-frame TIFF images are often used in medical imaging, scanned documents, and layered designs.
影像處理 API
Aspose.Imaging Cloud SDK for .NET 是一個基於 REST 架構的驚人 API,提供在線操縱和處理圖像的能力。它提供了一種簡單易用的方法,可以在 C# .NET 代碼片段中從多幀 TIFF 圖像中提取 TIFF 幀。該 SDK 可從 NuGet 和 GitHub 下載。現在,安裝 REST API 以開始操縱 TIFF 和其他圖像格式。
Install-Package Aspose.Imaging-Cloud
從 Aspose Cloud dashboard 獲取您的客戶端 ID 和客戶端密鑰。
使用 C# 提取 TIFF 幀
本節說明了如何使用 C# .NET 輕鬆提取 TIFF 幀的詳細信息。
- 首先,創建一個 ImagingApi 的物件,並提供 ClientID 和 ClientSecret 作為參數。
- 其次,創建一個 GetImageFrameRequest 對象,該對象以 TIFF 名稱、frameID 和其他參數作為參數。
- 現在,調用 GetImageFrame(..) 方法的 ImagingApi,並將
GetImageFrameRequest
對象作為輸入參數。 - 最後,保存提取的圖像。
// 從 https://dashboard.aspose.cloud/ 獲取 ClientID 和 ClientSecter
string clientID = "XXXXX-XXXXXXXXXX-bff4-f5a14a4b6466";
string clientSecret = "XXXXXXXXXX";
// 創建 ImagingApi 的實例
ImagingApi imagingApi = new ImagingApi(clientSecret, clientID,"https://api.aspose.cloud/","v3.0",false);
// 輸入的 TIFF 圖像可在雲端儲存中獲得
String fileName = "TiffSampleImage.tiff";
int? frameId = 5; // Index of a frame
int? newWidth = 300;
int? newHeight = 450;
int? x = 10;
int? y = 10;
int? rectWidth = 200;
int? rectHeight = 300;
string rotateFlipMethod = "RotateNoneFlipNone";
// 結果將僅包含指定的框架
bool? saveOtherFrames = false;
string folder = null; // Input file is saved at the root of the storage
string storage = null; // We are using default Cloud Storage
GetImageFrameRequest getImageFrameRequest = new GetImageFrameRequest(fileName, frameId, newWidth, newHeight,
x, y, rectWidth, rectHeight, rotateFlipMethod, saveOtherFrames, folder, storage);
Stream imageFrame = imagingApi.GetImageFrame(getImageFrameRequest);
// 將更新的影像儲存到本地存儲
using (var fileStream = File.Create("/Users/nayyer/Downloads/MyResultant.tiff"))
{
imageFrame.Seek(0, SeekOrigin.Begin);
imageFrame.CopyTo(fileStream);
}
我們可以提供任何值給 rotateFlipMethod 屬性。
RotateFlip 方法 (Rotate180FlipNone, Rotate180FlipX, Rotate180FlipXY, Rotate180FlipY, Rotate270FlipNone, Rotate270FlipX, Rotate270FlipXY, Rotate270FlipY, Rotate90FlipNone, Rotate90FlipX, Rotate90FlipXY, Rotate90FlipY, RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipXY, RotateNoneFlipY)。預設為 RotateNoneFlipNone。
使用 cURL 獲取 TIFF 幀
另外,我們也可以使用 cURL 命令來執行此操作。您可以考慮使用以下任一 API 調用來執行此操作。
- GET /imaging/{name}/frames/{frameId} - 從雲端儲存載入圖像並在回應中獲取圖像。
- POST /imaging/frames/{frameId} - 在請求主體中傳遞 TIFF,並在響應中獲取結果圖像。
第一步是根據您的 ClientID 和 ClientSecret 生成 JSON Web Token (JWT)。因此,請在終端機中執行以下命令以生成 JWT 令牌:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=XXXXXX-XXXXX-XXX-bff4-f5a14a4b6466&client_secret=XXXXXXXXXXX" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
現在,執行以下命令以從 TiffSampleImage.tiff 已上傳到雲端存儲的圖像中提取第二幀。
curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/TiffSampleImage.tiff/frames/2?saveOtherFrames=true" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-o myresultant.tiff
結論
從多幀 TIFF 圖像中提取個別幀的能力在處理掃描的多頁文檔、分層圖像文件或醫學影像數據集時非常有用。使用 Aspose.Imaging Cloud SDK for .NET,您可以輕鬆自動化此過程,無論是使用 REST API 調用還是 C# 代碼。
推薦文章
我們建議您訪問以下鏈接以了解: