Hello,
I would like to scan image shapes, find one that meets a specific criteria then replace the image with a new one that is exactly the same height/width and location.
I see from previous posts that the API does not handle creation of new image shapes. Can the API handle the substitution of an image within a shape for new one for the same shape?
thanks
Hi Dale,
Thank you for contacting support. Yes, you can get or set an array of shape image bytes. Please use the following code snippet:
[C#]
//Call the diagram constructor to load
diagram from a VSD file<o:p></o:p>
Diagram diagram = new Diagram("C:\\Drawing1.vsd");
// convert image into bytes array
byte[] imageBytes = File.ReadAllBytes("C:\\Desert.jpg");
//enter page index i.e. 0 for first one
foreach (Shape shape in diagram.Pages[0].Shapes)
{
//Filter shapes by type Foreign
if (shape.Type == Aspose.Diagram.TypeValue.Foreign)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(shape.ForeignData.Value))
{
//Load memory stream into bitmap object
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
if (bitmap.Height == 768 && bitmap.Width == 1024)
shape.ForeignData.Value = imageBytes;
}
}
}
diagram.Save("C:\\Output.vdx", SaveFileFormat.VDX);
I hope, this helps.