CompressImage()

IPictureFillFormat::CompressImage(bool, float) method

Compresses the image by reducing its size based on the shape size and specified resolution. Optionally, it also deletes cropped areas.

virtual bool Aspose::Slides::IPictureFillFormat::CompressImage(bool deleteCroppedAreasOfImage, float resolution)=0

Arguments

ParameterTypeDescription
deleteCroppedAreasOfImageboolIf true, the method will remove the cropped areas of the image, potentially further reducing its size.
resolutionfloatThe target resolution in DPI. This value must be positive and defines how the image will be resized.

Return Value

A bool indicating whether the image was successfully compressed. Returns true

Remarks

This method changes the image’s size and resolution similar to PowerPoint’s "Picture Format -> Compress Pictures" feature.

if the image was resized or cropped, otherwise false

.

The following example demonstrates how to use the CompressImage method to reduce the size of an image in a presentation by setting a target resolution and removing cropped areas:

System::SharedPtr<Presentation> presentation = System::MakeObject<Presentation>(u"demo.pptx");
System::SharedPtr<ISlide> slide = presentation->get_Slide(0);

// Gets the PictureFrame
System::SharedPtr<IPictureFrame> picFrame = System::AsCast<IPictureFrame>(slide->get_Shape(0));

// Compress the image with a target resolution of 150 DPI (Web resolution) and remove cropped areas
bool result = picFrame->get_PictureFormat()->CompressImage(true, 150.0f); // Web resolution

See Also