EPSのトリミングとサイズ変更
EPS画像のサイズを管理するネイティブC++ APIソリューション。
EPS画像の変換がさらに簡単になりました! Aspose.Page for C++を使用すると、わずか数行のコードでEPSファイルをトリミングしたり、正確な仕様サイズに変更したりできます。大きくしたいですか? 問題ありません。小さくする必要がありますか? お任せください。C++用APIを使用すれば画像を正確にスケーリングでき、お客様のビジョンにぴったりフィットするようにします。しかし、なぜEPS画像をトリミングしたりサイズ変更したりする必要があるのでしょうか?
- 印刷ドキュメントまたはデジタルドキュメントのレイアウトを設計している場合、特定の寸法に合わせるためにEPS画像のサイズを変更する必要がある場合があります。
- 画像サイズを縮小することでファイルサイズを減らし、共有、アップロード、または印刷を容易にすることができます。 画像ファイルが小さいほど、Webサイトやデジタルドキュメントでの読み込みも速くなり、ユーザーエクスペリエンスが向上します。
- トリミング(切り抜き)は、画像内の気を散らす、または関連のない部分を排除し、重要な要素に注意を集中させるのに役立ちます。また、デザインのニーズに合わせて画像のアスペクト比を変更することもできます。したがって、慎重なトリミングによって、画像の全体的な構図や視覚的な魅力を向上させることができます。
- トリミングとサイズ変更は、画像をWeb用途に最適化するのにも役立ち、画像がすばやく読み込まれ、さまざまな画面サイズで綺麗に見えるようにすることができます。
Aspose.Pageは、EPSファイルの境界を簡単に管理する機能を提供します。 このAPIを使用すると、C#を使って画像をスケーリングまたはトリミングできます。 EPSファイルの扱い方 について詳しくはドキュメントに従ってください。機能の実際の動作を確認するには、クロスプラットフォームアプリ EPS Crop と EPS Resize をお試しください。
この機能を使用するには、まずソリューションを取得する必要があります:
NuGetパッケージマネージャーを開き、Aspose.Pageを検索してインストールします。 パッケージマネージャーコンソールから次のコマンドを使用することもできます。
Package Manager Console Command
PM> Install-Package Aspose.Page
EPS画像のサイズを変更する手順。
以下の例は、選択した単位(ポイント)で.epsのサイズ変更処理を行う手順を示しています。順序は以下の通りです:
- EPSファイルを含む入力ストリームで PsDocument オブジェクトを初期化します。
- 静的メソッド ExtractEpsSize() を使用して画像の既存のサイズを定義します。
- 結果のEPSファイル用に出力ストリームを作成します。
- 静的メソッド ResizeEps() を使用して、ポイント単位の新しいサイズでPsDocumentオブジェクトのサイズを変更します。
- サイズ変更されたEPSファイルを保存します。
EPSのサイズ変更
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
//Create an input stream for EPS file
{
System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
// ------------------------------------------
try
{
//Initialize PsDocument object with input stream
System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
//Get size of EPS image
System::Drawing::Size oldSize = doc->ExtractEpsSize();
//Create an output stream for resized EPS
{
System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"output_resize_points.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
// ------------------------------------------
try
{
//Increase EPS size in 2 times and save to the output stream
doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(static_cast<float>(oldSize.get_Width() * 2), static_cast<float>(oldSize.get_Height() * 2)), Aspose::Page::Units::Points);
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
}
catch(...)
{
__dispose_guard_1.SetCurrentException(std::current_exception());
}
}
以下の例は、選択した単位(ポイント)で.epsのサイズ変更ではなくトリミング処理を行う手順を示しています。順序は以下の通りです:
- EPSファイルを含む入力ストリームで PsDocument オブジェクトを初期化します。
- 静的メソッド ExtractEpsBoundingBox() を使用して画像の既存のバウンディングボックス(境界枠)を定義します。
- 結果のEPSファイル用に出力ストリームを作成します。
- 静的メソッド CropEps() を使用して、新しいバウンディングボックスでPsDocumentオブジェクトをトリミングします。
- トリミングされたEPSファイルを保存します。
EPSのトリミング
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
//Create an input stream for EPS file
{
System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
// ------------------------------------------
try
{
//Initialize PsDocument object with input stream
System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
//Get initial bounding box of EPS image
System::ArrayPtr<int32_t> initialBoundingBox = doc->ExtractEpsBoundingBox();
//Create an output stream for resized EPS
{
System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"output_crop.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
// ------------------------------------------
try
{
//Create new bounding box
//Bounding box is represented by 4 numbers: x0, y0, x, y, where x0 - left margin, y0 - top margin, x - (x0 + width), y - (y0 + height)
System::ArrayPtr<float> newBoundingBox = System::MakeArray<float>({260, 300, 480, 432});
//Crop EPS image and save to the output stream
//Croping of image is changing of its bounding box so that new values of bounding box will be within initial bounding box, that is
//initialBoundingBox[0] <= newBoundingBox[0] <= initialBoundingBox[2]
//initialBoundingBox[1] <= newBoundingBox[1] <= initialBoundingBox[3]
//initialBoundingBox[0] <= newBoundingBox[2] <= initialBoundingBox[2]
//initialBoundingBox[1] <= newBoundingBox[3] <= initialBoundingBox[3]
doc->CropEps(outputEpsStream, newBoundingBox);
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
}
catch(...)
{
__dispose_guard_1.SetCurrentException(std::current_exception());
}
}
EPS EPS ファイル形式とは
EPS (Encapsulated PostScript) は、1 ページのレイアウトを記述する PostScript ベースのフォーマットです。ベクター画像やベクター‑ラスタ混合画像に最適です。インポート後は編集できないため、SVG や PDF など編集可能な形式に変換して使用します。