Qt使用QPainter绘制矢量图并保存为svg文件
位图和矢量图:
Bitmap:
- Usually a larger file size
- Cannot be enlarged into a higher resolution as the image quality will be affected
- Used to display complex images with many colors, such as photographs
Vector:
- Very small in file size
- Graphics can be resized without affecting the image quality
- Only a limited amount of color can be applied to each shape (single color, gradient, or pattern)
- Complex shapes require high-processing power to be generated
新建基于Widget的应用程序,继承于QMainWindow
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 |
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow public: virtual void paintEvent(QPaintEvent *event); public slots: private: #endif // MAINWINDOW_H |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() } void MainWindow::paintEvent(QPaintEvent *event) void MainWindow::actionSaveAsSVG() "", "SVG files (*.svg)"); void MainWindow::paintAll(QSvgGenerator *generator) // Draw Text |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include "MainWindow.h"
#include <QApplication> int main(int argc, char *argv[]) MainWindow w; return a.exec(); |
编译运行
另存为svg文件
最新文章
- 用crontab跑定时任务[转]
- JS,JQ点击事件
- Oracle ->;>; 连续聚合
- Quartz Scheduler 开发指南(1)
- springMVC+freemarker中Could not resolve view with name... 问题解决
- redundant 行记录格式
- python模块之json序列化
- android 休眠唤醒机制分析(二) — early_suspend
- Chapter 4. Using the Gradle Command-Line 使用gradle命令行
- bootstrap modal 弹出效果
- C语言链表的建立、插入和删除
- Spring学习之实例化bean的三种方式
- IIC_slaver 的仿真之路
- 普通PC安装ESXi5.5以及以上的方法
- 一本通1609【例 4】Cats Transport
- __getitem__()、__setitem__()与__delitem__()
- 二、基于kubernetes构建Docker集群环境实战
- HDU1007(最近点对)
- Scala学习之路 (六)Scala的类、对象、继承、特质
- Ubuntu忘记root密码的解决方法