Let me clarify on what we want exactly.
Our aim is to create a “Graphic” from the SVG. This has several advantages:
* When resizing it behaves like a vector image (sharp and precise).
* The line color can be set and it colors the shape properly.
This can be created in PowerPoint by dragging and dropping an SVG into the presentation or by choosing the ribbon button Insert -> Pictures and selecting the SVG file.
When viewing this “graphic” shape in PowerPoint it is obvious from the right-click context menu that it is a “Graphic”:
Context Menu on Graphic (http://i65.tinypic.com/s67wpx.png
)
However, I cannot create a “Graphic” like this in Aspose. When I create an image with Images.AddFromSvg, it behaves differently:
* When resizing it behaves like a vector image. This is good!
* The line color of this shape no longer colors the shape directly but the edge of the shape. This poses a problem for me.
Line recolor behaving differently (http://i63.tinypic.com/jjn0u8.png
)
It is also noticeable that this is not referred to as a “Graphic” in the right-click context menu but as a “Picture”:
Context Menu of Picture (http://i63.tinypic.com/2cyqihu.png
)
This is a problem for me as I want to create a shape with Aspose that is a “Graphic” (or behaves like a “Graphic”.
This is the code I’m using for inserting:
var svgContent = File.ReadAllText(@"path to svg\icons_house.svg");
var emfImage = presentation.Images.AddFromSvg(svgContent);
presentation.Slides[0].Shapes
.AddPictureFrame(ShapeType.Rectangle, 0, 0, emfImage.Width, emfImage.Height, emfImage);
These results can be observed on the first slide of the attached presentation.
The logic I’m trying to replicate was initially implemented in a PowerPoint VSTO Add-In.
In this Add-In, certain icons were added to the active presentation by copying and pasting it from an other presentation containing only icons.
This logic worked fine, I was able to copy the “Graphic” shape properly to the target presentation by the following code:
var originalShape = sourcePresentation.Slides[1].Shapes[1];
originalShape.Copy();
var resultShape = targetPresentation.Slides[1].Shapes.Paste()[1];
// resultShape.Line.ForeColor.RGB = Color.Red.Bgr();
The resulting shape is a direct copy of the source shape, the behavior is not changed, it is still a “Graphic”.
Context Menu on Copied Shape (http://i64.tinypic.com/k1tph0.png
)
These results can be observed on the second slide of the attached presentation.
When I try to recreate the same logic with Aspose (copy the shape from the exact same presentation), I get different results, as the result shape is a “Picture”. Also it is no longer vector graphics, but the backing image is a PNG instead. It is no longer sharp when resized and the image can no longer be recolored by changing the line color.
Recolor and Resize of copied shape (http://i63.tinypic.com/2egfcoy.png
)
This is a problem for me.
This is the code I’m using for copying:
var originalShape = sourcePresentation.Slides[0].Shapes[1]; // graphic
var originalPictureFrame = (PictureFrame)originalShape;
var image = targetPresentation.Images.AddImage(originalPictureFrame.PictureFormat.Picture.Image);
var resultShape = targetPresentation.Slides[1].Shapes
.AddPictureFrame(ShapeType.Rectangle, 0, 0, image.Width, image.Height, image);
If the original shape is created by Aspose (from an SVG file, with the code snippet you shared), it can be copied as an SVG to the other presentation, however it is still not what I want to achieve as the original shape was not colorable.
These results can be observed on the third slide of the attached presentation.
The presentation was created with PowerPoint 2019 but PowerPoint 2016 behaves in the exact same way.
Files: Aspose Copy Bug.zip (341.7 KB)