Rectángulo
Crear Rectángulo Simple
Al igual que los temas anteriores, este también trata sobre agregar una forma y esta vez la forma que discutiremos es el Rectángulo. En este tema, hemos descrito cómo los desarrolladores pueden agregar rectángulos simples o formateados a sus diapositivas utilizando Aspose.Slides para C++. Para agregar un rectángulo simple a una diapositiva seleccionada de la presentación, por favor siga los pasos a continuación:
- Cree una instancia de la clase Presentation.
- Obtenga la referencia de una diapositiva utilizando su índice.
- Agregue una IAutoShape de tipo Rectángulo utilizando el método AddAutoShape expuesto por el objeto IShapes.
- Escriba la presentación modificada como un archivo PPTX.
En el ejemplo dado a continuación, hemos añadido un rectángulo simple a la primera diapositiva de la presentación.
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); | |
Crear Rectángulo Formateado
Para agregar un rectángulo formateado a una diapositiva, por favor siga los pasos a continuación:
- Cree una instancia de la clase Presentation.
- Obtenga la referencia de una diapositiva utilizando su índice.
- Agregue una IAutoShape de tipo Rectángulo utilizando el método AddAutoShape expuesto por el objeto IShapes.
- Establezca el tipo de relleno del Rectángulo a Sólido.
- Establezca el color del Rectángulo utilizando la propiedad SolidFillColor.Color expuesta por el objeto FillFormat asociado con el objeto IShape.
- Establezca el color de las líneas del Rectángulo.
- Establezca el ancho de las líneas del Rectángulo.
- Escriba la presentación modificada como archivo PPTX. Los pasos anteriores se implementan en el ejemplo dado a continuación.
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); | |