如何将二维数组转换为 svg 或 png 格式的数独图像?

How to convert a 2d array to a sudoku image in svg or png format?

我正在尝试用 C++ 制作数独生成器,为此我将生成的拼图存储为二维矩阵。我怎样才能像数独一样生成该数组的 svg 图像或 png 图像?

我知道我可以使用很多工具,比如 svg++、Qt、simple-svg,从@Marek R 的回答来看,我认为 Qt 的 QImage 会很好,但我想知道有没有办法我可以加载现有的数独游戏,只更改其单元格中的值而不是自己绘制吗?在 Qt 中是否可行,如果不行,还有其他方法吗?

如果你会使用 Qt,那就很简单了:

void SomeClass::paintSvg(const QString &path)
{
    QSvgGenerator generator;
    generator.setFileName(path);
    generator.setSize(QSize(200, 200));
    generator.setViewBox(QRect(0, 0, 200, 200));
    generator.setTitle(tr("Sudoku problem"));
    generator.setDescription(tr("An SVG drawing created by the SVG Generator "
                                "Example provided with Qt."));

    QPainter painter;
    painter.begin(&generator);
    paintSudokuOn(painter);
    painter.end();
}

void SomeClass::paintPng(const QString &path) {
    QImage image { {200, 200}, QImage::Format_RGB32 };

    QPainter painter;
    painter.begin(&image);
    paintSudokuOn(painter);
    painter.end();

    image.save(path);
}

void SomeClass::paintSudokuOn(QPainter &painter) {
     // your code to do drawing
}

http://doc.qt.io/qt-5/qtsvg-svggenerator-example.html