C#を介してCMXを圧縮します
サーバー側APIを使用してCMXファイルを圧縮する独自の.NETアプリを作成します。
C#を使用してCMXファイルを圧縮する方法
公開用の画像の準備には、クリエイティブな側面とファイル圧縮などの技術的な側面の両方が必要です。高解像度の画像は印刷物や屋外広告には不可欠ですが、ファイル サイズが大きいため、Web パフォーマンスが低下する可能性があります。適切な画像圧縮技術は、目的と公開プラットフォームによって異なります。ファイルが大きいと、特にモバイル接続で読み込み時間が遅くなり、ユーザー エクスペリエンスが低下する可能性があります。ユーザーは、読み込みに時間がかかりすぎるサイトを放棄し、より高速な代替サイトを探す可能性があります。逆に、過剰な画像圧縮はぼやけやピクセル化を引き起こし、視聴体験を低下させる可能性があります。ファイル サイズと画質のバランスをとるには、圧縮アルゴリズムと圧縮率を適切に選択することが不可欠です。 CMX ファイルを圧縮するには、次を使用します。 Aspose.Imaging for .NET 機能が豊富で強力で使いやすいC#プラットフォーム用の画像操作および変換APIであるAPI。開ける NuGet パッケージマネージャー、検索 ** Aspose.Imaging ** とインストールします。パッケージマネージャーコンソールから次のコマンドを使用することもできます。
パッケージマネージャーコンソールコマンド
PM> Install-Package Aspose.Imaging
C#を介してCMXを圧縮する手順
あなたは aspose.imaging.dll 自分の環境で次のワークフローを試してください。
- Image.Loadメソッドを使用してCMXファイルをロードします +画像を圧縮します。
- Aspose.Imaging形式でサポートされているディスクに圧縮画像を保存します
システム要求
Aspose.Imaging for .NETは、すべての主要なオペレーティングシステムでサポートされています。次の前提条件があることを確認してください。
-Microsoft Windows、または.NET Framework、.NET Core、Windowsアプリケーション、ASP.NETWebアプリケーションと互換性のあるOS。 -Microsoft VisualStudioのような開発環境。 -プロジェクトで参照されているAspose.Imagingfor.NET。
CMX画像を圧縮する-.NET
using Aspose.Imaging.FileFormats.Bmp; | |
using Aspose.Imaging.FileFormats.Dicom; | |
using Aspose.Imaging.FileFormats.Emf; | |
using Aspose.Imaging.FileFormats.Jpeg; | |
using Aspose.Imaging.FileFormats.Jpeg2000; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.FileFormats.Psd; | |
using Aspose.Imaging.FileFormats.Tiff.Enums; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Masking; | |
using Aspose.Imaging.Masking.Options; | |
using Aspose.Imaging.Masking.Result; | |
using Aspose.Imaging.Sources; | |
using Aspose.Imaging; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
CompressVectorFormatsToEmf(); | |
void CompressVectorFormatToSvg() | |
{ | |
List<string> formatExts = new List<string>() { "cdr", "cmx", "odg", "otg", "eps" }; | |
formatExts.ForEach | |
( | |
formatExt => | |
{ | |
var inputFile = Path.Combine(templatesFolder, $"template.{formatExt}"); | |
var outputFile = Path.Combine(templatesFolder, $"compressed_{formatExt.ToUpper()}"); | |
using (var image = Image.Load(inputFile)) | |
{ | |
Func<VectorRasterizationOptions> rasterizationOptionsFactory = () => | |
{ | |
switch (image.FileFormat) | |
{ | |
case FileFormat.Cdr: | |
return new CdrRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Cmx: | |
return new CmxRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Odg: | |
return new OdgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Otg: | |
return new OtgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
default: | |
return null; | |
} | |
}; | |
if (image is IMultipageImage multiPage && multiPage.PageCount > 1) | |
{ | |
for (var pageIndex = 0; pageIndex < multiPage.PageCount; pageIndex++) | |
{ | |
multiPage.Pages[pageIndex].Save($"{outputFile}_p{pageIndex + 1}.svgz", new SvgOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete($"{outputFile}_p{pageIndex + 1}.svgz"); | |
} | |
} | |
else | |
{ | |
image.Save(outputFile + ".svgz", new SvgOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete(outputFile + ".svgz"); | |
} | |
} | |
} | |
); | |
} | |
void CompressVectorFormatToWmf() | |
{ | |
List<string> formatExts = new List<string>() { "cdr", "cmx", "odg", "otg", "eps" }; | |
formatExts.ForEach | |
( | |
formatExt => | |
{ | |
var inputFile = Path.Combine(templatesFolder, $"template.{formatExt}"); | |
var outputFile = Path.Combine(templatesFolder, $"compressed_{formatExt.ToUpper()}"); | |
using (var image = Image.Load(inputFile)) | |
{ | |
Func<VectorRasterizationOptions> rasterizationOptionsFactory = () => | |
{ | |
switch (image.FileFormat) | |
{ | |
case FileFormat.Cdr: | |
return new CdrRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Cmx: | |
return new CmxRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Odg: | |
return new OdgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Otg: | |
return new OtgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
default: | |
return null; | |
} | |
}; | |
if (image is IMultipageImage multiPage && multiPage.PageCount > 1) | |
{ | |
for (var pageIndex = 0; pageIndex < multiPage.PageCount; pageIndex++) | |
{ | |
multiPage.Pages[pageIndex].Save($"{outputFile}_p{pageIndex + 1}.wmz", new WmfOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete($"{outputFile}_p{pageIndex + 1}.wmz"); | |
} | |
} | |
else | |
{ | |
image.Save(outputFile + ".wmz", new WmfOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete(outputFile + ".wmz"); | |
} | |
} | |
} | |
); | |
} | |
void CompressVectorFormatsToEmf() | |
{ | |
List<string> formatExts = new List<string>() { "cdr", "cmx", "odg", "otg", "eps" }; | |
formatExts.ForEach | |
( | |
formatExt => | |
{ | |
var inputFile = Path.Combine(templatesFolder, $"template.{formatExt}"); | |
var outputFile = Path.Combine(templatesFolder, $"compressed_{formatExt.ToUpper()}"); | |
using (var image = Image.Load(inputFile)) | |
{ | |
Func<VectorRasterizationOptions> rasterizationOptionsFactory = () => | |
{ | |
switch (image.FileFormat) | |
{ | |
case FileFormat.Cdr: | |
return new CdrRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Cmx: | |
return new CmxRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Odg: | |
return new OdgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
case FileFormat.Otg: | |
return new OtgRasterizationOptions() { PageWidth = image.Width, PageHeight = image.Height }; | |
default: | |
return null; | |
} | |
}; | |
if (image is IMultipageImage multiPage && multiPage.PageCount > 1) | |
{ | |
for (var pageIndex = 0; pageIndex < multiPage.PageCount; pageIndex++) | |
{ | |
multiPage.Pages[pageIndex].Save($"{outputFile}_p{pageIndex + 1}.emz", new EmfOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete($"{outputFile}_p{pageIndex + 1}.emz"); | |
} | |
} | |
else | |
{ | |
image.Save(outputFile + ".emz", new EmfOptions() | |
{ | |
Compress = true, | |
VectorRasterizationOptions = rasterizationOptionsFactory.Invoke() | |
}); | |
File.Delete(outputFile + ".emz"); | |
} | |
} | |
} | |
); | |
} |
Aspose.Imaging for .NET APIについて
Aspose.Imaging APIは、アプリケーション内で画像(写真)を作成、変更、描画、または変換するための画像処理ソリューションです。クロスプラットフォームの画像処理(さまざまな画像形式間の変換(均一なマルチページまたはマルチフレームの画像処理を含む)、描画などの変更、グラフィックプリミティブの操作、変換(サイズ変更、トリミング、反転、回転)を含むがこれらに限定されない) 、2値化、グレースケール、調整)、高度な画像操作機能(フィルタリング、ディザリング、マスキング、デスキュー)、およびメモリ最適化戦略。これはスタンドアロンライブラリであり、画像操作をソフトウェアに依存しません。プロジェクト内のネイティブAPIを使用して、高性能の画像変換機能を簡単に追加できます。これらは100%プライベートのオンプレミスAPIであり、画像はサーバーで処理されます。オンラインアプリを介してCMXを圧縮する
[Live Demos Webサイト](https://products.aspose.app/imaging/image-compress)にアクセスして、CMXドキュメントを圧縮します。 ライブデモには次の利点があります
CMX とは CMX ファイル形式
CMX拡張子の付いたファイルは、CorelSuiteアプリケーションによるプレゼンテーションとして使用されるCorelExchangeイメージファイル形式です。これには、ベクターグラフィックとしての画像データと、画像を説明するメタデータが含まれています。 CMXファイルは、CorelDraw、Corel Presentations、Paint Shop Pro、およびAdobeIllustratorの一部のバージョンで開くことができます。
続きを読むその他のサポートされている圧縮形式
C#を使用すると、を含むさまざまな形式を簡単に圧縮できます。