長方形

シンプルな長方形を作成する

前のトピックと同様に、今回は形状を追加することについてであり、今回議論する形状は長方形です。このトピックでは、開発者がAspose.Slides for C++を使用してスライドにシンプルまたはフォーマットされた長方形を追加する方法を説明しています。プレゼンテーションの選択したスライドにシンプルな長方形を追加するには、以下の手順に従ってください。

  1. Presentation クラスのインスタンスを作成します。
  2. インデックスを使用してスライドの参照を取得します。
  3. IShapesオブジェクトによって公開されたAddAutoShapeメソッドを使用して、長方形型のIAutoShapeを追加します。
  4. 修正されたプレゼンテーションをPPTXファイルとして書き込みます。

以下の例では、プレゼンテーションの最初のスライドにシンプルな長方形を追加しました。

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 outPath = u"../out/SimpleRectangle.pptx";
const String templatePath = u"../templates/HelloWorld.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add autoshape of ellipse type
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 150, 150, 50);
// Save PPTX to Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

フォーマットされた長方形を作成する

スライドにフォーマットされた長方形を追加するには、以下の手順に従ってください。

  1. Presentation クラスのインスタンスを作成します。
  2. インデックスを使用してスライドの参照を取得します。
  3. IShapesオブジェクトによって公開されたAddAutoShapeメソッドを使用して、長方形型のIAutoShapeを追加します。
  4. 長方形の塗りつぶしタイプをソリッドに設定します。
  5. IShapeオブジェクトに関連付けられたFillFormatオブジェクトによって公開されたSolidFillColor.Colorプロパティを使用して、長方形の色を設定します。
  6. 長方形の線の色を設定します。
  7. 長方形の線の幅を設定します。
  8. 修正されたプレゼンテーションをPPTXファイルとして書き込みます。 上記の手順は、以下の例で実装されています。
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 outPath = u"../out/FormattedRectangle_out.pptx";
const String templatePath = u"../templates/AltText.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
// Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an autoshape of type line
SharedPtr<IAutoShape> shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 150, 150, 75);
// Set the fill color of the rectangle shape
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_White());
// Apply some formatting on the line
shape->get_LineFormat()->set_Style(LineStyle::ThickThin);
shape->get_LineFormat()->set_Width(7);
shape->get_LineFormat()->set_DashStyle(LineDashStyle::Dash);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
//Write the PPTX to Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);