Adding image into Presentation loses vector graphics using Aspose.Slides for .NET

I have a Presentation with a house icon on it. The icon was drawn in Sketch then pasted into the presentation.

It resulted in a “PictureFrame” which still contains vector graphics:
1. In PowerPoint this shape can be right-clicked to open the “Format Graphic” dialog, there I can set the line and fill properties which colors the shape.
2. I can also right-click and select “Convert to Shape” which converts it into two Freeform Shapes.
3. I can rescale the shape to any size and it looks sharp.

If I copy this shape in PowerPoint and paste it into another presentation it retains all its properties and works fine.

I’m trying to copy this shape with Aspose.Slides. NET 18.12.0.0 (I also tried 18.2.1.0), but it results in a PictureFrame containing a PNG instead of the vector graphics

I’m running the following code:

var image = sourceSlide.Presentation.Images.AddImage(sourcePictureFrame.PictureFormat.Picture.Image);
var newPictureFrame = targetSlide.AddPictureFrame(ShapeType.Rectangle, l, t, w, h, image);

I would expect it to result in a similar PictureFrame containing vector graphics, it’s a PictureFrame contanining a PNG.

Is there any way to get the result I want?

@csanadya,

I have observed your comments. Can you please share source file along with sample code and generated result so that we may further investigate to help you out.

Thanks very much. The source files are here: PictureFrame_Result.zip (62.7 KB)
On both, the house was resized for better understanding.
Thanks,
csanadya

@csanadya,

Thank you for the elaboration. I have tried opening the source presentation both in PowerPoint 2016 and PowerPoint 2010 but have not been able to find following options as specified by you.

Can you please share the snapshot, how you have set these options. I have obtained this image when I right clicked your image in both PowerPoint 2016 and 2010.

Secondly, Aspose.Slides does allow you to add vector images in presentation. I suggest you to please visit documentation article, Add SVG in slide for your reference.

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)

@csanadya,

I have observed your requirements in detail and an issue with ID SLIDESNET-40858 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESNET-40858) have been fixed in this update.