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.
The issues you found earlier (filed as SLIDESJAVA-39657) have been resolved in Aspose.Slides for Java 25.7 (Maven, JAR).
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.
@dfinsolutions,
Since Microsoft’s images are licensed and protected by copyright, and their license terms prohibit their reuse in third-party libraries or applications, including those textures would violate legal restrictions. (These effect textures used by PowerPoint can be found at %localappdata%\Microsoft\GraphicsCache\1\CloudGraphicsResources\Graphics\
.)
Therefore, a system was implemented that allows developers to assign their own images (textures) for visual ink effects. This approach provides flexibility and creative freedom while fully respecting intellectual property rights.
The following static property has been added:
public static IGenericDictionary<Integer, IImage> getInkEffectImages()
This property allows you to define or override the images used to render various visual ink effects. Each value in the InkEffectType
enumeration can be associated with a custom texture.
Example usage:
IImage image = Images.fromFile("image.png");
Ink.getInkEffectImages().addItem(InkEffectType.Galaxy, image);
You can configure one or more effects by adding the corresponding InkEffectType
→IImage
pairs to the InkEffectImages
dictionary. These textures are automatically used when rendering Ink objects.
Additionally, a new property has been added to the IInkBrush
interface and the InkBrush
class:
public final int getInkEffect()
This property enables you to determine which visual ink effect is assigned to a particular brush. The value is read from the brush’s “inkEffects” property. If no effect is specified or the value is unrecognized, InkEffectType.NotDefined
is returned.
The following enumeration has also been added: InkEffectType