@GetMapping("/searchApprovalBpmn")
    public void searchApprovalBpmn(String instanceId, HttpServletResponse response) throws UnsupportedEncodingException {

        response.setContentType("image/jpg");
//        response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(instanceId+".jpg", "UTF-8"));
//        response.setDateHeader("expries", -1);
//        response.setHeader("Cache-Control", "no-cache");
//        response.setHeader("Pragma", "no-cache");
        TaskService taskService = processEngine.getTaskService();
        Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
        BpmnModel bpmnModel;
        List activeActivityIds;
        if (task != null) {
            bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
            activeActivityIds = runtimeService.getActiveActivityIds(task.getExecutionId());
        } else {
            HistoricTaskInstance taskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(instanceId).list().get(0);
            bpmnModel = repositoryService.getBpmnModel(taskInstance.getProcessDefinitionId());
            activeActivityIds = new ArrayList<>();
        }

        Map map = bpmnModel.getItemDefinitions();
        DefaultProcessDiagramGenerator diagramGenerator = new DefaultProcessDiagramGenerator();
        String os = System.getProperty("os.name").toLowerCase();
        String font = "SimSun";
        if (os.startsWith("win")) {
            font = "宋体";
        }
        try (InputStream in = diagramGenerator.generateDiagram(bpmnModel, "jpg", activeActivityIds, activeActivityIds,
                font, font, font,
                processEngine.getProcessEngineConfiguration().getProcessEngineConfiguration().getClassLoader(), 1.0);
             BufferedInputStream bin = new BufferedInputStream(in);
             OutputStream out = response.getOutputStream();
             BufferedOutputStream bout = new BufferedOutputStream(out);
        ) {
            // 读取生成的流程图
            BufferedImage image = ImageIO.read(bin);

            // 获取流程图的实际内容区域
            Rectangle bounds = getDiagramBounds(image);

            // 创建新的裁剪后的图像
            BufferedImage croppedImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = croppedImage.createGraphics();

            // 在新图像中绘制裁剪后的内容
            g2d.drawImage(image, 0, 0, bounds.width, bounds.height, bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, null);
            g2d.dispose();

            // 输出裁剪后的图像
            ImageIO.write(croppedImage, "jpg", bout);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 获取流程图的实际内容区域
    private Rectangle getDiagramBounds(BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();

        int minX = width;
        int minY = height;
        int maxX = 0;
        int maxY = 0;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if (image.getRGB(x, y) != Color.WHITE.getRGB()) {
                    if (x < minX) minX = x;
                    if (y < minY) minY = y;
                    if (x > maxX) maxX = x;
                    if (y > maxY) maxY = y;
                }
            }
        }

        return new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
    }


这个是我查看工作流进度的方法，但是生成出来的图片大小不一，你能不能帮我优化一下，请输出完整的代码