Java Swing - PUmlApi
package jlib5.java; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; import net.sourceforge.plantuml.BlockUml; import net.sourceforge.plantuml.BlockUmlBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.Option; import net.sourceforge.plantuml.core.Diagram; public class PUmlApi { public static List<BufferedImage> makeImage(String input) throws IOException, InterruptedException { @SuppressWarnings("deprecation") BlockUmlBuilder builder = new BlockUmlBuilder( new ArrayList<String>(), //option.getConfig(), "UTF-8", //option.getCharset(), new Option().getDefaultDefines(), new StringReader(input)); List<BufferedImage> result = new ArrayList<>(); for( BlockUml blockUml : builder.getBlockUmls() ) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); final Diagram diagram = blockUml.getDiagram(); diagram.exportDiagram((OutputStream)os, 0, new FileFormatOption(FileFormat.PNG)); result.add(ImageIO.read(new ByteArrayInputStream(os.toByteArray()))); os.close(); } catch (Exception e) { e.getSuppressed(); } } return result; } }
댓글 없음:
댓글 쓰기