利用drawo.io将xml转化为JPG

一、背景

上文工作利用diagrams渲染mermaid为xml文件

利用diagrams渲染mermaid为xml文件-CSDN博客http://t.csdnimg.cn/HAlON

现在需要将xml转化为JPG文件,投喂给大模型,提升大模型的图表能力。

如果再利用drawo.io的网页端,再进行另存为图片,就太慢了。

在GitHub有一个大神,他提供开源的桌面端drwao.io,有了它,就不用等网页渲染了,效率拉满。

       

二、方法

        下载drawo.io后, 遍历输入目录中的文件,使用 draw.io.exe 将 .xml文件 转换为 .jpg文件。这样就可以批量处理xml文件了。

import os
from tqdm import tqdm

# 定义输入和输出目录
base_dir = r'xml'
output_dir = r'output'
os.makedirs(output_dir, exist_ok=True)

# 遍历输入目录中的文件,逆序进行
for name in tqdm(os.listdir(base_dir)[::-1]):
    # 跳过不是 .xml 结尾的文件
    if not name.endswith('.xml'):
        continue
    # 如果输出目录中已经存在相应的 .jpg 文件,跳过处理
    if os.path.exists(os.path.join(output_dir, name[:-4] + '.jpg')):
        continue

    # 定义转换后的 .jpg 文件路径
    xml_path = os.path.join(base_dir, name)
    jpg_name = os.path.join(output_dir, name[:-4] + '.jpg')

    # 使用 draw.io.exe 将 .xml 转换为 .jpg
    os.system(f'draw.io.exe -x -f jpg -o "{jpg_name}" "{xml_path}"')

三、结果

是真的快,用网页渲染,又要好久好久。

四、后续工作

  • 将输出的JPG与xml中的数据进行准确映射,去除无法准确贴上标签的数据。
  • 将xml提取element和edge元素存储在JSON文件中,作为数据的标签。

将JPG流程图与xml中的数据进行准确映射-CSDN博客

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
好的,我可以帮你写一个简单的井字棋游戏,使用Processing编写。以下是代码: ```java // 定义格子大小 int CELL_SIZE = 100; // 定义棋盘 char[][] board = new char[3][3]; char currentPlayer = 'X'; void setup() { size(300, 300); stroke(0); strokeWeight(4); textAlign(CENTER, CENTER); textSize(50); initBoard(); } void draw() { background(255); drawBoard(); drawPieces(); checkWin(); } // 初始化棋盘 void initBoard() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { board[i][j] = '-'; } } } // 绘制棋盘 void drawBoard() { for (int i = 1; i < 3; i++) { line(CELL_SIZE * i, 0, CELL_SIZE * i, height); line(0, CELL_SIZE * i, width, CELL_SIZE * i); } } // 绘制棋子 void drawPieces() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == 'X') { drawX(i, j); } else if (board[i][j] == 'O') { drawO(i, j); } } } } // 绘制X void drawX(int row, int col) { int x = col * CELL_SIZE + CELL_SIZE / 2; int y = row * CELL_SIZE + CELL_SIZE / 2; line(x - CELL_SIZE / 3, y - CELL_SIZE / 3, x + CELL_SIZE / 3, y + CELL_SIZE / 3); line(x - CELL_SIZE / 3, y + CELL_SIZE / 3, x + CELL_SIZE / 3, y - CELL_SIZE / 3); } // 绘制O void drawO(int row, int col) { int x = col * CELL_SIZE + CELL_SIZE / 2; int y = row * CELL_SIZE + CELL_SIZE / 2; ellipse(x, y, CELL_SIZE / 1.5, CELL_SIZE / 1.5); } // 检查是否获胜 void checkWin() { char winner = '-'; // 检查行 for (int i = 0; i < 3; i++) { if (board[i][0] != '-' && board[i][0] == board[i][1] && board[i][1] == board[i][2]) { winner = board[i][0]; } } // 检查列 for (int i = 0; i < 3; i++) { if (board[0][i] != '-' && board[0][i] == board[1][i] && board[1][i] == board[2][i]) { winner = board[0][i]; } } // 检查对角线 if (board[0][0] != '-' && board[0][0] == board[1][1] && board[1][1] == board[2][2]) { winner = board[0][0]; } if (board[0][2] != '-' && board[0][2] == board[1][1] && board[1][1] == board[2][0]) { winner = board[0][2]; } // 显示获胜者 if (winner != '-') { textSize(100); fill(255, 0, 0); text(winner, width / 2, height / 2); noLoop(); } } // 点击事件 void mousePressed() { if (currentPlayer == 'X') { int row = mouseY / CELL_SIZE; int col = mouseX / CELL_SIZE; if (board[row][col] == '-') { board[row][col] = currentPlayer; currentPlayer = 'O'; } } } ``` 这个程序会创建一个3x3的井字棋棋盘。玩家可以点击棋盘的格子来下棋,程序会检查是否有获胜者。如果有获胜者,程序会在屏幕上显示获胜者的棋子,并停止运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gatinaa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值