Hello,
I need to extract images of individual shapes from a Visio Diagram.
Following code does not work:
-------------------------------------------------
System.Drawing.Image image = SourceDiagram.Masters.Shapes[0].Image;
-------------------------------------------------
So I tried this logic:
-------------------------------------------------
Aspose.Diagram.Diagram NewDiagram = new Aspose.Diagram.Diagram();
Aspose.Diagram.Page page0 = NewDiagram.Pages[0];
page0.Shapes.Add(SourceDiagram.Masters.Shapes[0]);
NewDiagram.Save(savePath + "shape0.jpg", Aspose.Diagram.SaveFileFormat.JPEG);
-------------------------------------------------
This code works but the problem is that I get new image height/width as big as of original diagram. So new image contains a lot of extra white space.
I need new image to be of same size as the shape (without extra white space).
-Raman
Hi Ramandeep,
Thank you for your interest in our Aspose.Diagram product. In your code, you are converting whole Visio diagram to a JPG file format. You can extract images from a page by using following code snippet:
In addition, there are some evaluation limitations. You can avoid evaluation limitations by getting a temporary license for 30 days and try the latest version on your end because it seems like you are using an old version of Aspose.Diagram for .NET. Please visit download page here:
http://www.aspose.com/community/files/51/.net-components/aspose.diagram-for-.net/default.aspx
You can learn all about how Aspose products are licensed by checking out the Licenses FAQ here: Purchase Portal
In case of ambiguity please share sample documents. We’ll take a closer look and guide you accordingly.
Hello Imran,
Thanks for quick reply!
I am already using latest version 2.9.
I don’t need to extract images that are embedded in diagram.
Rather I need to save individual master shapes as images.
Can you suggest any solution or may be a correction in my sample code that I mentioned above - to make image of correct size and avoid extra white space in output image?
Thanks
Raman
Hi Ramandeep,
Thank you for your details. I would like to update you that you can adjust the page size to fit the shape image. You can also change shape position and then you can convert it to an image file format. When you have a circle as a shape you cannot export it to image without white space around as the image is always a rectangle. This is not Aspose.Diagram product restriction. I've attached a sample test case along with a code snippet.
Please let us know in case of further assistance and comments.
Hi Imran,
Thanks for your reply.
when I click on ‘Get a temporary license’ button.
I have tried code that you suggested but it truncates shape image from one side and leaves a lot of extra white space on other sides. I have attached one .VSS file and a few output image files.
-------------------------------------------------
i = 0;
Aspose.Diagram.Shapes shapes = SourceDiagram.Masters.Shapes;
foreach (Aspose.Diagram.Shape shape in shapes)
{
Aspose.Diagram.Diagram NewDiagram = new Aspose.Diagram.Diagram();
Aspose.Diagram.Page page0 = NewDiagram.Pages[0];
page0.PageSheet.PageProps.PageHeight.Value = shape.XForm.Height.Value + 1.0;
page0.PageSheet.PageProps.PageWidth.Value = shape.XForm.Width.Value + 1.0;
shape.XForm.PinX.Value = 1.0;
shape.XForm.PinY.Value = 1.0;
page0.Shapes.Add(shape);
i += 1;
NewDiagram.Save(savePath + “shape” + i + “.jpg”, Aspose.Diagram.SaveFileFormat.JPEG);
}
-------------------------------------------------
Any other ideas?
-Raman
Hi Ramandeep,
Please accept our apologies for the delay. We are working over your query and will get back to you as soon as possible.
Hi Ramandeep,
Thank you for your details. You can get a temporary license for 30 days by posting your request at Aspose.Purchase forum.
Or you can request one at step 4 of the Get Pricing Information wizard:
http://www.aspose.com/purchase/default.aspx
Second, you need to adjust these settings for each shape separately because in your provided VSS file shape width and height vary with each other.
Diagram SourceDiagram = new Diagram(@"C:\AD\test0\3D.vss");
Aspose.Diagram.Master master = SourceDiagram.Masters[0];
Shape shape = master.Shapes[0];
Diagram NewDiagram = new Diagram();
Page page0 = NewDiagram.Pages[0];
page0.PageSheet.PageProps.PageHeight.Value = 1.9;
page0.PageSheet.PageProps.PageWidth.Value = 2.2;
shape.XForm.PinX.Value = 1;
shape.XForm.PinY.Value = 0.6;
page0.Shapes.Add(shape);
NewDiagram.Save(@"C:\AD\test0\imgs\Output.jpg", Aspose.Diagram.SaveFileFormat.JPEG);
Please let us know in case of further assistance and comments.
Hello Imran,
You mentioned, "… you need to adjust these settings for each shape separately …"
But I can not hard-code anything for specific shapes because user can upload any kind of .vss files on my website and I need to extract images of master shapes in correct size - without truncation and without extra space.
Is it possible using ASPose?
Also let me know, if there is a way to work with .vss files created using Visio versions older than 2003.
Thanks
Raman
Hi Ramandeep,
I'm sorry about this inconvenience. I've logged this problem in our bug tracking system under ticket Id DIAGRAM-33306. Second, a new feature request to support older Visio formats has already been logged into our issue tracking system as DIAGRAM-28689. Your request has been linked to the appropriate issues. We will inform you through this forum thread as soon as this feature is available for public use.
The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.