Hello,
I’m trying to parse a PowerPoint document and save the drawing/ink as an image, but the colors of the drawings in the saved image are different from those in the PowerPoint file.
Is there a way to preserve the original colors?
Code:
@Test
void parseInk() {
Presentation presentation = new Presentation("C:\\work\\ppt\\drawing.pptx");
IGroupShape group = (IGroupShape) presentation.getSlides().get_Item(0).getShapes().get_Item(0);
group.getShapes().get_Item(0).getImage().save("c:\\work\\ppt\\drawing1.png");
group.getShapes().get_Item(1).getImage().save("c:\\work\\ppt\\drawing2.png");
group.getShapes().get_Item(2).getImage().save("c:\\work\\ppt\\drawing3.png");
}
PPT file and differences example:
drawing.zip (127.0 KB)
@dfinsolutions
To preserve the original colors of the ink drawings when saving them as images from a PowerPoint presentation, you can utilize the IInkOptions
interface introduced in version 23.12 of the Aspose.Slides API. This interface allows you to control how ink objects are rendered, specifically addressing the issue of color discrepancies.
You can set the InterpretMaskOpAsOpacity
property to false
to ensure that the ink objects are exported as they are displayed in PowerPoint, rather than using the default transparency settings. Here’s how you can modify your code to implement this:
@Test
void parseInk() {
Presentation presentation = new Presentation("C:\\work\\ppt\\drawing.pptx");
RenderingOptions options = new RenderingOptions();
options.getInkOptions().setInterpretMaskOpAsOpacity(false); // Preserve original colors
// Save the ink drawings as images
for (int i = 0; i < presentation.getSlides().get_Item(0).getShapes().size(); i++) {
IGroupShape group = (IGroupShape) presentation.getSlides().get_Item(0).getShapes().get_Item(i);
for (int j = 0; j < group.getShapes().size(); j++) {
Bitmap bmp = group.getShapes().get_Item(j).getImage().getThumbnail(options);
bmp.save("c:\\work\\ppt\\drawing" + (i + 1) + "_" + (j + 1) + ".png");
}
}
}
In this code, we create a RenderingOptions
object and set the InterpretMaskOpAsOpacity
property to false
. This should help in maintaining the original colors of the ink drawings when they are saved as images.
Make sure you are using version 23.12 or later of the Aspose.Slides library to access this feature.
If you continue to experience issues, please check the documentation for any additional settings that may affect rendering or consider reaching out for further assistance.
@dfinsolutions,
I need some time to check the issue. I will get back to you as soon as possible.
@dfinsolutions,
Thank you for your patience. I’ve reproduced the issue with the drawing color when converting the Ink objects to images.
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): SLIDESJAVA-39657
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.