We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Inserting an image into .vsdx file


I’ve tried everything so far to try and insert an image into a visio doc. All of the examples you currently have for images is replacing the shapes and then setting their values such as:

for (Shape shape : (Iterable) newDig.getPages().getPage(0).getShapes()) {

// Filter shapes by type Foreign

x = shape;

if (shape.getType() == TypeValue.FOREIGN) {

// replace picture shape




However I would like to insert an image into the doc as a shape from scratch and not simply replace shapes. The problem that I encounter is that this image does not have a master or at least I can't find an appropriate master.

Could you provide me with a code example of how I create a shape from lets say

byte[] imageData and insert it into a visio doc?

Hi John,

Thank you for contacting support. Please refer to this sample code:


// Create a new diagram
Diagram diagram = new Diagram();

// Get page object by index
Page page0 = diagram.getPages().get(0);
// Set pinX, pinY, width and height
double pinX = 2, pinY = 2, width = 4, hieght = 3;

// Import Bitmap image as Visio shape
page0.addShape(pinX, pinY, width, hieght, “c:\temp\image.bmp”);

// Save Visio diagram
diagram.save(“InsertImageInVisio_Out.vsdx”, SaveFileFormat.VSDX);

Hello Imran,
I am also dealing with same issue. I want to insert in image that fits into rectangle shape. I have used your code mentioned above but its not working for me. Following exception occured:

com.aspose.diagram.DiagramException: Master with name {0} does not present in the collection of Masters.
at com.aspose.diagram.gv.a(Unknown Source)
at com.aspose.diagram.Page.b(Unknown Source)
at com.aspose.diagram.Page.addShape(Unknown Source)
at com.test.DynamicConnector.main(DynamicConnector.java:57)

My Code :
String visioStencil = “C:\temp\” + “AddConnectShapes.vss”;
String rectangleMaster = “Rectangle”, connectorMaster = “Dynamic connector”;

int pageNumber = 0;
double width = 2, height = 2, pinX = 4.25, pinY = 9.5;

Diagram diagram = new Diagram(visioStencil);

diagram.addMaster(“C:\temp\Basic Shapes.vss”, rectangleMaster);
diagram.addMaster(“C:\temp\Basic Shapes.vss”, connectorMaster);

long rectangleId = page.addShape(pinX, pinY, width, height, “C:\Users\Downloads\port2.bmp”);


Kindly send us your stencil and image files. We will investigate your scenario in our environment and share our findings with you.