#include
#include
#include "qcustomplot.h"
#include
#include
#include
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// 创建 QCustomPlot 对象并绘制图形
QCustomPlot customPlot;
customPlot.addGraph();
QVector xData = {1, 2, 3, 4, 5};
QVector yData = {1, 4, 9, 16, 25};
customPlot.graph(0)->setData(xData, yData);
customPlot.rescaleAxes();
customPlot.replot();
// 创建 QPixmap 对象并将 QCustomPlot 渲染到 QPixmap 上
QPixmap pixmap(customPlot.size());
customPlot.render(&pixmap);
// 创建 QByteArray 对象并将 QPixmap 写入 QByteArray 中
QByteArray byteArray;
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // 可以选择其他图像格式,如 "JPG" 或 "BMP"
buffer.close();
qDebug() << "Image saved to QByteArray.";
return a.exec();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36