C++中壓縮TIFF的代碼

用於優化TIFF內容和大小的高性能C++庫,保留原始質量和基線數據

這是在C++中優化和壓縮TIFF的專業解決方案。使用C++最大限度地提高TIFF優化/壓縮速度。免費在線試用!

查看代碼片段

在 C++ 中壓縮 TIFF 文件

使大的 TIFF 文件更小而不損失質量。刪除不必要和未使用的數據。在代碼中縮小 TIFF 文件的大小。 C++ 庫為開發人員提供了一個集成的 API 來優化 TIFF 內容。

使用 C++ 減小 TIFF 文件的大小

C++ 庫是一個獨立的解決方案,不需要安裝任何第三方軟件。

使用 'Aspose.Words for C++' 可以輕鬆實現無損壓縮和深度內容優化。以下示例演示瞭如何優化 C++ 中的 C++ TIFF 文件的內容:

C++中用於壓縮TIFF文件的代碼示例
上傳要優化/壓縮的文件
運行代碼
從列表中選擇目標格式
dotnet add package Aspose.Words.Cpp
複製
using namespace Aspose::Words;

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);

auto shape = builder->InsertImage(u"Input.tiff");

// 更新頁面設置以裁剪文檔以適合圖片的大小。
auto pageSetup = builder->get_PageSetup();
pageSetup->set_PageWidth(shape->get_Width());
pageSetup->set_PageHeight(shape->get_Height());
pageSetup->set_TopMargin(0);
pageSetup->set_LeftMargin(0);
pageSetup->set_BottomMargin(0);
pageSetup->set_RightMargin(0);

auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Tiff);
saveOptions->set_TiffCompression(TiffCompression::Lzw);

doc->Save(u"Output.tiff", saveOptions);
using namespace Aspose::Words; auto doc = MakeObject<Document>(u"Input.tiff"); doc->Cleanup(); auto nodes = doc->GetChildNodes(NodeType::Shape, true); for (const auto& shape : System::IterateOver<Shape>(nodes)) { if (shape->get_HasImage()) { // 由開發人員選擇用於圖像壓縮的庫。 auto image = System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream()); // ... // 壓縮圖像並將其設置回形狀。 shape->get_ImageData()->SetImage("yourCompressedImage"); } } auto saveOptions = MakeObject<PdfSaveOptions>(); saveOptions->set_CacheBackgroundGraphics(true); doc->Save(u"Output.tiff", saveOptions); using namespace Aspose::Words; auto doc = MakeObject<Document>(u"Input.tiff"); doc->Cleanup(); auto nodes = doc->GetChildNodes(NodeType::Shape, true); for (const auto& shape : System::IterateOver<Shape>(nodes)) { if (shape->get_HasImage()) { // 由開發者選擇用於圖像壓縮的庫。 auto image = System::Drawing::Image::Fromstream(shape->get_ImageData()->ToStream()); // ... // 壓縮圖像並將其設置回形狀。 shape->get_ImageData()->SetImage("yourCompressedImage"); } } doc->Save(u"Output.tiff"); using namespace Aspose::Words; auto doc = MakeObject<Document>(u"Input.tiff"); doc->Cleanup(); auto nodes = doc->GetChildNodes(NodeType::Shape, true); for (const auto& shape : System::IterateOver<Shape>(nodes)) { if (shape->get_HasImage()) { // 由開發人員選擇用於圖像壓縮的庫。 auto image = System::Drawing::Image::FromStream(shape->get_ImageData()->ToStream()); // ... // 壓縮圖像並將其設置回形狀。 shape->get_ImageData()->SetImage("yourCompressedImage"); } } auto saveOptions = MakeObject<OoxmlSaveOptions>(); saveOptions->set_CompressionLevel(CompressionLevel::Maximum); doc->Save(u"Output.tiff", saveOptions); using namespace Aspose::Words; auto doc = MakeObject<Document>(); auto builder = MakeObject<DocumentBuilder>(doc); auto shape = builder->InsertImage(u"Input.tiff"); // 更新頁面設置以裁剪文檔以適合圖片的大小。 auto pageSetup = builder->get_PageSetup(); pageSetup->set_PageWidth(shape->get_Width()); pageSetup->set_PageHeight(shape->get_Height()); pageSetup->set_TopMargin(0); pageSetup->set_LeftMargin(0); pageSetup->set_BottomMargin(0); pageSetup->set_RightMargin(0); auto saveOptions = MakeObject<ImageSaveOptions>(SaveFormat::Tiff); saveOptions->set_TiffCompression(TiffCompression::Lzw); doc->Save(u"Output.tiff", saveOptions);
運行代碼

如何壓縮TIFF

  1. 安裝Aspose.Words for C++ 。
  2. 將庫引用(導入庫)添加到您的C++項目。
  3. 在C++中打開源TIFF文件。
  4. 在不損失質量的情況下壓縮TIFF 。
  5. 調用Document.Cleanup()方法。結果代碼可能因輸出文件格式而異。
  6. 將壓縮結果作為TIFF文件獲取。

C++庫用於優化和壓縮TIFF個文件

有三個選項可以將 Aspose.Words for C++ 安裝到您的開發人員環境中。請選擇符合您需求的一種,並按照分步說明進行操作:

系統要求

您可以使用這個 C++ 庫在 Microsoft Windows 、Linux 和 macOS 操作系統上開發軟件:

  • Linux 需要 GCC >= 6.3.0 和 Clang >= 3.9.1
  • Xcode >= 12.5.1 ,macOS 需要 Clang 和 libc++

如果您為 Linux 或 macOS 開發軟件,請查看產品文檔中 fontconfig 和 mesa-glu 開源包)的信息。

其他支持的文件格式優化

您可以優化許多其他文件格式的文件:

5%

訂閱 Aspose 產品更新

獲取直接發送到您的郵箱的每月通訊和優惠。

© Aspose Pty Ltd 2001-2024. 版權所有。