PSからJPEGへの変換
C++ 用 API ソリューションを介して PS を JPEG に変換します。
PostScript (PS) はページ記述言語であり、強力な反面、直接操作が複雑になる場合があります。PS ファイルは、他の形式に比べて直接編集が広くサポートされているとは言えません。Adobe Acrobat や Ghostscript などのアプリケーションは PS ファイルを開いて解釈できますが、直接編集は最新の形式に比べて容易ではありません。多くのユーザーにとって、PS ファイルをより扱いやすい形式に変換することは望ましいことです。この API は、堅牢な変換機能を提供することで、このニーズに応えます。
C++ 開発者は Aspose.Page を活用することで、PostScript ファイルを JPEG などの幅広い形式に効率的に変換できます。この API は、C++ アプリケーション内で PS 変換を処理するための堅牢で統合しやすいソリューションを提供します。
PS を JPEG に変換するには:
Aspose.Page for C++ API は、機能が豊富で強力で使いやすい、C++ プラットフォーム用のドキュメント操作および変換 API です。
最新バージョンを直接ダウンロードできます。NuGet パッケージ マネージャーを開いて、Aspose.Page.Cpp を検索してインストールします。パッケージ マネージャー コンソールから次のコマンドを使用することもできます。
Package Manager Console Command
PM> Install-Package Aspose.Page.Cpp
C++ を使用して PS を JPEG に変換する手順
Aspose.Page を使用すると、開発者はわずか数行のコードで PS ファイルをロードして JPEG に変換することが簡単になります。
- Aspose.Page for C++ を使用して PS ファイルを読み込みます。
- ImageSaveOptions Class のオブジェクトを作成し、画像形式を ImageFormat::Jpeg 。
- 定義されたオプションを使用して SaveAsImage を呼び出して画像のバイト配列を取得します。
- 画像バイトを出力ストリームに書き込むことで画像を保存します。
このコード サンプルでは、PS から JPEG C++ への変換について説明します。
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
// Initialize PsDocument with the name of PostScript file.
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>();
//Set output image format.
options->set_ImageFormat(Aspose::Page::Drawing::Imaging::ImageFormat::Jpeg);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
// Save PS document as array of image bytes, one bytes array for one page.
System::ArrayPtr<System::ArrayPtr<uint8_t>> imagesBytes = document->SaveAsImage(options);
//Save images bytes arrays as image files.
int32_t i = 0;
for (System::ArrayPtr<uint8_t> imageBytes : imagesBytes)
{
System::String imagePath = System::IO::Path::GetFullPath(dataDir + u"out_image" + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(options->get_ImageFormat()).ToLower());
{
System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ fs});
// ------------------------------------------
try
{
fs->Write(imageBytes, 0, imageBytes->get_Length());
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
i++;
}
//Review errors
if (suppressErrors)
{
for (auto&& ex : System::IterateOver(options->get_Exceptions()))
{
System::Console::WriteLine(ex->get_Message());
}
}
PS What is PS File Format
PS (PostScript) は、テキストとグラフィックを 1 ファイルに統合するページ記述言語です。多くの画像編集・印刷ソフトでサポートされ、プリンタ向けの描画指示を含みます。
JPEG What is JPEG File Format
JPEG は、写真向けの有損圧縮形式で、画質とファイルサイズのバランスが取れています。高圧縮時に画質が低下します。