プレゼンテーションビューア
スライドからSVG画像を生成する
Aspose.Slides for C++は、スライドを含むプレゼンテーションファイルを作成するために使用されます。これらのスライドは、Microsoft PowerPointを使用してプレゼンテーションを開くことで表示できます。しかし、場合によっては、開発者が好きな画像ビューアでスライドをSVG画像として表示する必要があるかもしれません。そのような場合、Aspose.Slides for C++では、個々のスライドをSVG画像にエクスポートできます。この記事では、この機能の使用方法を説明します。Aspose.Slides.Pptx for C++を使用して任意のスライドからSVG画像を生成するには、以下の手順に従ってください。
- Presentationクラスのインスタンスを作成します。
- IDまたはインデックスを使用して、目的のスライドの参照を取得します。
- メモリストリーム内にSVG画像を取得します。
- メモリストリームをファイルに保存します。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = u"../templates/TestDeck_050.pptx"; | |
const String outPath = u"../out/Aspose_out.svg"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Access the first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Create a memory stream object | |
SharedPtr<System::IO::MemoryStream> SvgStream = MakeObject<System::IO::MemoryStream>(); | |
// Generate SVG image of slide and save in memory stream | |
slide->WriteAsSvg(SvgStream); | |
SvgStream->set_Position(0); | |
// Save memory stream to file | |
try | |
{ | |
System::SharedPtr<System::IO::Stream> fileStream = System::IO::File::OpenWrite(outPath); | |
System::ArrayPtr<uint8_t> buffer = System::MakeObject<System::Array<uint8_t>>(8 * 1024, 0); | |
int32_t len; | |
while ((len = SvgStream->Read(buffer, 0, buffer->get_Length())) > 0) | |
{ | |
fileStream->Write(buffer, 0, len); | |
} | |
} | |
catch (Exception e) | |
{ | |
} | |
SvgStream->Close(); | |
カスタム形状IDでSVGを生成する
現在、Aspose.Slides for C++は、カスタム形状IDを持つスライドからSVGを生成するために使用できます。これらのスライドは、Microsoft PowerPointを使用してプレゼンテーションを開くことで表示できます。しかし、場合によっては、開発者が好きな画像ビューアでスライドをSVG画像として表示する必要があるかもしれません。そのような場合、Aspose.Slides for C++では、個々のスライドをSVG画像にエクスポートできます。その目的のために、生成されたSVG内の形状のカスタムIDをサポートするためにISvgShapeにIDプロパティが追加されました。この機能を実装するために、形状IDを設定するために使用できるCustomSvgShapeFormattingControllerが導入されました。
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
/*class CustomSvgShapeFormattingController::ISvgShapeFormattingController | |
{ | |
void CustomSvgShapeFormattingController() | |
{ | |
public: | |
int m_shapeIndex; | |
CustomSvgShapeFormattingController(int shapeStartIndex = 0) | |
{ | |
m_shapeIndex = shapeStartIndex; | |
} | |
public void FormatShape(ISvgShape svgShape, IShape shape) | |
{ | |
svgShape.Id = string.Format("shape-{0}", m_shapeIndex++); | |
} | |
}; | |
}; | |
*/ | |
void GeneratingSVGWithCustomShapeIDS() | |
{ | |
// The path to the documents directory. | |
const String templatePath = L"../templates/TestDeck_050.pptx"; | |
const String outPath = L"../out/GeneratingSVGWithCustomShapeIDS_out.svg"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
SharedPtr<SVGOptions> svgOptions = MakeObject< SVGOptions>(); | |
SharedPtr<CustomSvgShapeFormattingController>customSvgShapeFormattingController = MakeSharedPtr<CustomSvgShapeFormattingController>(0); | |
svgOptions->set_ShapeFormattingController(customSvgShapeFormattingController); | |
// Access the first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Create a memory stream object | |
SharedPtr<System::IO::MemoryStream> SvgStream = MakeObject<System::IO::MemoryStream>(); | |
// Generate SVG image of slide and save in memory stream | |
slide->WriteAsSvg(SvgStream); | |
SvgStream->set_Position(0); | |
// Save memory stream to file | |
try | |
{ | |
System::SharedPtr<System::IO::Stream> fileStream = System::IO::File::OpenWrite(outPath); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard __dispose_guard_1{ fileStream, ASPOSE_CURRENT_FUNCTION }; | |
// ------------------------------------------ | |
System::ArrayPtr<uint8_t> buffer = System::MakeObject<System::Array<uint8_t>>(8 * 1024, 0); | |
int32_t len; | |
while ((len = SvgStream->Read(buffer, 0, buffer->get_Length())) > 0) | |
{ | |
fileStream->Write(buffer, 0, len); | |
} | |
} | |
catch (Exception e) | |
{ | |
} | |
SvgStream->Close(); | |
} | |
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
/*class CustomSvgShapeFormattingController: public ISvgShapeFormattingController | |
{ | |
int m_shapeIndex; | |
CustomSvgShapeFormattingController(int shapeStartIndex = 0) | |
{ | |
m_shapeIndex = shapeStartIndex; | |
} | |
public: | |
void FormatShape(SvgShape svgShape, Shape shape) | |
{ | |
svgShape.set_Id(String::Format(L"Shape-{0}", m_shapeIndex++)); | |
} | |
};*/ | |
/*void CustomSvgShapeFormattingController::FormatShape(SvgShape svgShape, Shape shape) | |
{ | |
svgShape.set_Id(String::Format(L"Shape-{0}", m_shapeIndex++)); | |
}*/ | |
スライドサムネイル画像を作成する
Aspose.Slides for C++は、スライドを含むプレゼンテーションファイルを作成するために使用されます。これらのスライドは、Microsoft PowerPointを使用してプレゼンテーションファイルを開くことで表示できます。しかし、場合によっては、開発者が好きな画像ビューアでスライドを画像として表示する必要があるかもしれません。そのような場合、Aspose.Slides for C++は、スライドのサムネイル画像を生成するのに役立ちます。Aspose.Slides for C++を使用して任意のスライドのサムネイルを生成するには:
- Presentationクラスのインスタンスを作成します。
- IDまたはインデックスを使用して、任意のスライドの参照を取得します。
- 指定されたスケールで参照スライドのサムネイル画像を取得します。
- 任意の画像形式でサムネイル画像を保存します。
// Presentationクラスのインスタンスを作成
auto presentation = MakeObject<Presentation>(u"ThumbnailFromSlide.pptx");
// 最初のスライドにアクセス
auto slide = presentation->get_Slide(0);
// フルスケール画像を作成
auto image = slide->GetImage(1, 1);
image->Save(u"Thumbnail_out.jpg", ImageFormat::Png);
image->Dispose();
presentation->Dispose();
ユーザー定義の寸法でサムネイルを作成する
- Presentationクラスのインスタンスを作成します。
- IDまたはインデックスを使用して、任意のスライドの参照を取得します。
- 指定されたスケールで参照スライドのサムネイル画像を取得します。
- 任意の画像形式でサムネイル画像を保存します。
// Presentationクラスのインスタンスを作成
auto presentation = MakeObject<Presentation>(u"ThumbnailWithUserDefinedDimensions.pptx");
// 最初のスライドにアクセス
auto slide = presentation->get_Slide(0);
// ユーザー定義の寸法
auto desiredX = 1200;
auto desiredY = 800;
auto slideSize = presentation->get_SlideSize()->get_Size();
// XおよびYのスケール値を取得
auto scaleX = (float)(1.0 / slideSize.get_Width()) * desiredX;
auto scaleY = (float)(1.0 / slideSize.get_Height()) * desiredY;
// カスタムスケール画像を作成
auto image = slide->GetImage(scaleX, scaleY);
image->Save(u"Thumbnail2_out.jpg", ImageFormat::Png);
image->Dispose();
presentation->Dispose();
ノートスライドビューでスライドからサムネイルを作成する
Aspose.Slides for C++を使用してノートスライドビューで任意のスライドのサムネイルを生成するには:
- Presentationクラスのインスタンスを作成します。
- IDまたはインデックスを使用して、任意のスライドの参照を取得します。
- ノートスライドビューで指定されたスケールで参照スライドのサムネイル画像を取得します。
- 任意の画像形式でサムネイル画像を保存します。
以下のコードスニペットは、ノートスライドビューでプレゼンテーションの最初のスライドのサムネイルを生成します。
// Presentationクラスのインスタンスを作成
auto presentation = MakeObject<Presentation>(u"ThumbnailFromSlideInNotes.pptx");
// 最初のスライドにアクセス
auto slide = presentation->get_Slide(0);
// ユーザー定義の寸法
auto desiredX = 1200;
auto desiredY = 800;
auto slideSize = presentation->get_SlideSize()->get_Size();
// XおよびYのスケール値を取得
auto scaleX = (float)(1.0 / slideSize.get_Width()) * desiredX;
auto scaleY = (float)(1.0 / slideSize.get_Height()) * desiredY;
// フルスケール画像を作成
auto image = slide->GetImage(scaleX, scaleY);
image->Save(u"Notes_tnail_out.jpg", ImageFormat::Png);
image->Dispose();
presentation->Dispose();