public StreamResource buildStreamResource(
      ProcessInstance processInstance,
      RepositoryService repositoryService,
      RuntimeService runtimeService) {

    StreamResource imageResource = null;

    ProcessDefinitionEntity processDefinition =
        (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                .getDeployedProcessDefinition(processInstance.getProcessDefinitionId());

    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
      InputStream definitionImageStream =
          ProcessDiagramGenerator.generateDiagram(
              processDefinition,
              "png",
              runtimeService.getActiveActivityIds(processInstance.getId()));

      StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);

      // Create image name
      String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
      String fileName = processInstance.getId() + UUID.randomUUID() + "." + imageExtension;

      imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
    }
    return imageResource;
  }
  /**
   * 显示图片
   *
   * @return
   */
  @RequestMapping(value = "/viewPic.do")
  public void viewPic(
      HttpServletRequest request,
      HttpServletResponse response,
      @RequestParam("executionId") String executionId)
      throws Exception {
    ProcessInstance processInstance =
        runtimeService.createProcessInstanceQuery().processInstanceId(executionId).singleResult();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    // 使用spring注入引擎请使用下面的这行代码
    Context.setProcessEngineConfiguration(processEngine.getProcessEngineConfiguration());

    InputStream imageStream =
        ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", activeActivityIds);

    // 输出资源内容到相应对象
    byte[] b = new byte[1024];
    int len;
    while ((len = imageStream.read(b, 0, 1024)) != -1) {
      response.getOutputStream().write(b, 0, len);
    }
  }