モダン API で画像処理を強化
概要
現在、Aspose.Slides for C++ ライブラリは、System::Drawing の以下のクラスに対する依存関係を公開 API に持っています。
バージョン 24.4 以降、この公開 API は非推奨と宣言されています。
System::Drawing への依存を公開 API から取り除くために、いわゆる「Modern API」を追加しました。System::Drawing::Image および System::Drawing::Bitmap を使用するメソッドは非推奨とされ、Modern API の対応メソッドに置き換えられます。System::Graphics を使用するメソッドも非推奨とされ、公開 API からのサポートは削除されます。
System::Drawing への依存を持つ非推奨の公開 API の削除は、リリース 24.8 で行われます。
Modern API
公開 API に次のクラスと列挙型を追加しました。
- Aspose::Slides::IImage - ラスター画像またはベクタ画像を表します。
- Aspose::Slides::ImageFormat - 画像のファイル形式を表します。
- Aspose::Slides::Images - IImage インターフェイスのインスタンス化と操作用メソッドを提供します。
新しい API の典型的な使用シナリオは以下のようになります:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
// ディスク上のファイルから IImage の破棄可能インスタンスを作成します。
System::SharedPtr<IImage> image = Images::FromFile(u"image.png");
// IImage のインスタンスをプレゼンテーションの画像コレクションに追加して PowerPoint 画像を作成します。
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
// スライド #1 に画像シェイプを追加します
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
// スライド #1 を表す IImage のインスタンスを取得します。
auto slideImage = pres->get_Slide(0)->GetImage(System::Drawing::Size(1920, 1080));
// 画像をディスクに保存します。
slideImage->Save(u"slide1.jpeg", Aspose::Slides::ImageFormat::Jpeg);
古いコードを Modern API に置き換える
移行を容易にするために、新しい IImage のインターフェイスは Image および Bitmap クラスの個別シグネチャを再現しています。基本的には、System::Drawing を使用した古いメソッド呼び出しを新しいものに置き換えるだけです。
スライドサムネイルの取得
非推奨 API を使用したコード:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetThumbnail()->Save(u"slide1.png");
Modern API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->GetImage()->Save(u"slide1.png");
シェイプサムネイルの取得
非推奨 API を使用したコード:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetThumbnail()->Save(u"shape.png");
Modern API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
pres->get_Slide(0)->get_Shape(0)->GetImage()->Save(u"shape.png");
プレゼンテーションサムネイルの取得
非推奨 API を使用したコード:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
auto bitmaps = pres->GetThumbnails(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));
for (int32_t index = 0; index < bitmaps->get_Length(); index++)
{
System::SharedPtr<System::Drawing::Bitmap> thumbnail = bitmaps[index];
thumbnail->Save(System::String::Format(u"slide_{0}.png", index), System::Drawing::Imaging::ImageFormat::get_Png());
}
Modern API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");
auto images = pres->GetImages(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));
for (int32_t index = 0; index < images->get_Length(); index++)
{
System::SharedPtr<IImage> thumbnail = images[index];
thumbnail->Save(System::String::Format(u"slide_{0}.png", index), Aspose::Slides::ImageFormat::Png);
}
プレゼンテーションへの画像追加
非推奨 API を使用したコード:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(u"image.png");
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
Modern API:
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
System::SharedPtr<Aspose::Slides::IImage> image = Aspose::Slides::Images::FromFile(u"image.png");
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
削除されるメソッド/プロパティと Modern API での置き換え
Presentation クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options) | GetImages(System::SharedPtr<Export::IRenderingOptions> options) |
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) |
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) |
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) |
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) |
| GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) | GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) |
| Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format) | 完全に削除されます |
| Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format, System::SharedPtr<Export::ISaveOptions> options) | 完全に削除されます |
Slide クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| GetThumbnail() | GetImage() |
| GetThumbnail(float scaleX, float scaleY) | GetImage(float scaleX, float scaleY) |
| GetThumbnail(System::Drawing::Size imageSize) | GetImage(System::Drawing::Size imageSize) |
| GetThumbnail(System::SharedPtr<Export::ITiffOptions> options) | GetImage(System::SharedPtr<Export::IRenderingOptions> options |
| GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options) | GetImage(System::SharedPtr<Export::IRenderingOptions> options) |
| GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) | GetImage(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) |
| GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) | GetImage(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) |
| RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics) | 完全に削除されます |
| RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, float scaleX, float scaleY) | 完全に削除されます |
| RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, System::Drawing::Size renderingSize) | 完全に削除されます |
Shape クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| GetThumbnail() | GetImage() |
| GetThumbnail(ShapeThumbnailBounds bounds, float scaleX, float scaleY) | GetImage(ShapeThumbnailBounds bounds, float scaleX, float scaleY) |
ImageCollection クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| AddImage(System::SharedPtr<System::Drawing::Image> image) | AddImage(System::SharedPtr<IImage> image) |
PPImage クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| ReplaceImage(System::SharedPtr<System::Drawing::Image> newImage) | ReplaceImage(System::SharedPtr<Aspose::Slides::IImage> newImage) |
| get_SystemImage() | get_Image() |
PatternFormat クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) | GetTile(System::Drawing::Color background, System::Drawing::Color foreground) |
| GetTileImage(System::Drawing::Color styleColor) | GetTile(System::Drawing::Color styleColor) |
IPatternFormatEffectiveData クラス
| メソッド シグネチャ | 置換 メソッド シグネチャ |
|---|---|
| GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) | GetTileIImage(System::Drawing::Color background, System::Drawing::Color foreground) |
System::Drawing::Graphics の API サポートは廃止されます
System::Drawing::Graphics を使用したメソッドは非推奨とされ、公開 API からのサポートは削除されます。
この API の該当部分は次のとおり削除されます:
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>)
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>, float, float)
- Slide::RenderToGraphics(System::SharedPtr<Export::IRenderingOptions>, System::SharedPtr<System::Drawing::Graphics>, System::Drawing::Size)
FAQ
System::Drawing::Graphics が削除された理由は何ですか?
Graphics のサポートは、レンダリングと画像の取り扱いを統一し、プラットフォーム固有の依存関係を排除し、IImage を使用したクロスプラットフォーム アプローチに切り替えるために、公開 API から削除されます。Graphics に対するすべてのレンダリングメソッドは削除されます。
IImage は Image/Bitmap と比べて実際にどんな利点がありますか?
IImage はラスタ画像とベクタ画像の両方を統一的に扱い、ImageFormat を介したさまざまな形式への保存を簡素化し、System::Drawing への依存を減らし、環境間でのコード移植性を向上させます。
Modern API はサムネイル生成のパフォーマンスに影響しますか?
GetThumbnail から GetImage への切り替えはシナリオを悪化させません。新しいメソッドはオプションやサイズ指定で画像を生成する同等の機能を提供し、レンダリングオプションのサポートも保持しています。具体的な性能の向上または低下はシナリオ次第ですが、機能的には同等です。