2019년 8월 25일 일요일

[PlantUML] PlantUML to BufferedImage




public static List<BufferedImage> makeImage(String input) throws IOException, InterruptedException {
 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;
}

댓글 없음:

댓글 쓰기