Hi guys, I’m having some issues with programatically setting an IImageShapeUIModel’s images.
After the script runs the element appears on the screen but appears without an image. Manually setting an image afterwards works but I need the script to set the image correctly.
Would really appreciate being pointed in the right direction! Here is my code to try to get it working…
IImageShapeUIModel imageShape = (IImageShapeUIModel) diagramManager.createDiagramElement(technologiesDiagram, IModelElementFactory.instance().createImageShape());
String imagePath = "/Users/{my_name}/Documents/AppEngine.png";
imageShape.setImagePath(imagePath);
imageShape.setEmbeddedPath(imagePath);
imageShape.setDisplayImagePath(imagePath);
imageShape.setLinkedFilePath(imagePath);
imageShape.setMode(IImageShapeUIModel.EMBEDDED);
BufferedImage image = null;
try {
File file = new File(imagePath);
image = ImageIO.read(file);
imageShape.setImage(image);
System.out.println(file.getAbsolutePath());
} catch (Exception ex) {
ex.printStackTrace();
}
imageShape.setBounds(100, 100, 284, 137);
System.out.println(imageShape.getEmbeddedPath()); //PRINTS SAME AS IMAGEPATH
System.out.println(imageShape.getDisplayImagePath()); //PRINTS SAME AS IMAGEPATH
System.out.println(imageShape.getImagePath()); //PRINTS SAME AS IMAGEPATH
System.out.println(imageShape.getLinkedFilePath()); //PRINTS SAME AS IMAGEPATH
Image test = imageShape.getImage();
System.out.println(test.equals((Image) image)); //PRINTS TRUE
In my actual script the url file path as a string is correct I edited it to remove personal information