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.