I am using Aspose.Slides for C++ 25.4 version , to convert all shapes to images. I have a ppt with math equations.
srcShape->GetImage()
Throws an exception:
System::ArgumentNullException: Value can not be null.: image
I can put checks to avoid exception like:
if (!srcShape || !srcShape->GetImage())
{
return nullptr;
}
But Is there any way to get the thumbnail image for these math equations?
PPT attached:
Test1.pptx.zip (255.3 KB)
@pankajku
It seems that you’re encountering a System::ArgumentNullException
when trying to get the image of a shape, particularly with math equations in your PowerPoint presentation using Aspose.Slides for C++. This exception indicates that the image cannot be null, suggesting that the shape you are trying to access may not support image generation directly.
To work around this issue, you can generate a thumbnail image for the shape instead. Aspose.Slides allows you to create thumbnails for shapes, which can be a suitable alternative for visual representation of shapes that do not have an image.
Here’s a simple example on how to create a thumbnail for a shape:
auto presentation = MakeObject<Presentation>(u"YourPresentation.pptx");
auto shape = presentation->get_Slide(0)->get_Shape(0); // Get the desired shape
// Generate a thumbnail image with default scaling
auto image = shape->GetImage(); // This may throw an exception for some shapes
// If the above fails, you can try generating a thumbnail with defined bounds
auto bounds = ShapeThumbnailBounds::Appearance; // or ShapeThumbnailBounds::Shape
auto scale = 1; // Scaling factor
image = shape->GetImage(bounds, scale, scale);
image->Save(u"Shape_thumbnail_out.png", ImageFormat::Png);
image->Dispose();
presentation->Dispose();
In this example, you first attempt to get the image. If it fails, you can utilize the GetImage
method with specific bounds and scaling to create a thumbnail of the shape, which should work even for shapes that do not generate direct images.
Make sure that you adjust the ShapeThumbnailBounds
based on your requirement to either capture the shape’s appearance or its bounds. This should help you retrieve a visual representation of your math equations without running into null exceptions.
If you need further assistance, feel free to ask!
Sources:
[1]: Shape Thumbnails|Aspose.Slides Documentation
Tried the following code. Still not able to get thumbnail image.
System::SharedPtr<IImage> image;
try {
// First try to get image directly
if (srcShape) {
image = srcShape->GetImage();
}
}
catch (const std::exception& e) {
}
// If direct GetImage() failed or returned null, try with ShapeThumbnailBounds
if (!image && srcShape) {
try {
auto bounds = Aspose::Slides::ShapeThumbnailBounds::Appearance;
auto scale = 1; // Scaling factor
image = srcShape->GetImage(bounds, scale, scale);
}
catch (const std::exception& e) {
return nullptr;
}
}
if (!image) {
return nullptr;
}
@pankajku,
Thank you for reporting on the issue. I’ve reproduced the problem with appearing the ArgumentNullException
when using the following code snippet:
auto bounds = Aspose::Slides::ShapeThumbnailBounds::Appearance;
auto scale = 1;
image = srcShape->GetImage(bounds, scale, scale);
We are sorry that you encountered this problem.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESCPP-4038
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@pankajku,
The issues you found earlier (filed as SLIDESCPP-4038) have been resolved in Aspose.Slides for C++ 25.8 (NuGet (x64), NuGet (x86), Windows, Linux, macOS).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.