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

Free Support Forum - aspose.com

Error saving templates with PNG Images

When I use the following method from your examples to try to make a stencil file with PNG images:

public static Master createMaster(final int masterId, final String name, final java.awt.Image image) throws Exception {
	// set master properties
	Master ms = new Master();
	ms.setID(masterId);
	ms.setName(name);
	ms.setIconSize(1);
	ms.setAlignName(2);
	ms.setMatchByName(0);
	ms.setIconUpdate(1);
	
	ms.setPatternFlags(0);
	ms.setHidden(0);

	// set master's shape properties
	final Shape shape = new Shape();
	ms.getShapes().add(shape);

	final String encodedImage = loadImage(image);
	final double width = 0.5443889263424177;
	final double height = 0.432916947568133;

	shape.setID(5);
	shape.setType(TypeValue.FOREIGN);

	shape.getXForm().getPinX().setValue(0.2221944631712089);
	shape.getXForm().getPinY().setValue(0.1666458473784065);
	shape.getXForm().getWidth().setValue(width);
	shape.getXForm().getHeight().setValue(height);
	shape.getXForm().getLocPinX().getUfe().setF("Width*0.5");
	shape.getXForm().getLocPinY().getUfe().setF("Height*0.5");
	shape.getXForm().getResizeMode().setValue(0);

	shape.getTextXForm().getTxtPinY().getUfe().setF("-TxtHeight/2");
	shape.getTextXForm().getTxtWidth().getUfe().setF("TEXTWIDTH(TheText)");
	shape.getTextXForm().getTxtHeight().getUfe().setF("TEXTHEIGHT(TheText, TxtWidth)");

	// set connection properties
	final Connection connection = new Connection();
	shape.getConnections().add(connection);

	connection.setID(1);
	connection.setNameU("All");
	connection.getX().setValue(0.22);
	connection.getX().getUfe().setF("Width*0.5");
	connection.getY().setValue(0.16);
	connection.getY().getUfe().setF("Height*0.5");
	connection.getDirX().setValue(0);
	connection.getDirY().setValue(0);
	connection.getType().setValue(0);
	connection.getAutoGen().setValue(BOOL.FALSE);
	connection.getPrompt().getUfe().setF("No Formula");

	shape.getForeignData().setForeignType(ForeignType.BITMAP);
	shape.getForeignData().setCompressionType(CompressionType.PNG);
	shape.getForeignData().setValue(encodedImage.getBytes());

	return ms;
}

I get the following exception when i try to save the file:

java.lang.IllegalStateException: Cannot convert image type to string.

The PNG files I am using look correct.

@Thinian

Can you please share the link to this code example as well? We will check and test the scenario in our environment and address it accordingly.

When I run this example it happens:

I tried both:

diagram.save(dataDir + “template_Out.vtx”, SaveFileFormat.VTX);
// diagram.save(dataDir + “template_Out.vssx”, SaveFileFormat.VSSX);

The first has no error, but the image is empty, the second throws the “can not convert” exception.

That’s one of yours.

@Thinian

We are checking it and will get back to you shortly.

Thanks…apparently it takes at least 12 characters to say that…

@Thinian

We have found an issue in the example and we have logged a ticket as DIAGRAMJAVA-51072 in order to get it fixed. The ticket has been associated with this forum thread and you will be notified as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issue is marked as resolved, so what is the solution?

@Thinian

The fix is scheduled to be included in 23.2 version of the API which will be released in February 2023.

Ok, thanks. I can wait