目錄
1. 問題的提出
2. 問題解決
1. 問題的提出
? ? ? 今天通過一張像素為141 *?214,大小為426KB的svg格式的圖片構(gòu)造QGraphicsSvgItem對象,再通過Qt的Graphics View Framework框架,將QGraphicsSvgItem對象顯示到場景視圖上,代碼如下:
#include <QElapsedTimer>
#include <QGraphicsSvgItem>
...... // 其它頭文件略
...... // 其它代碼略
auto pBatteryChargeGraphicsScene = new QGraphicsScene(this);
ui->graphicsView->setScene(pBatteryChargeGraphicsScene);
QElapsedTimer timer;
timer.start();
auto pPeiDianGuiComponent = new QGraphicsSvgItem(QStringLiteral(":/uavGuarantee/image/batteryChargeShelters/peidiangui.svg"));
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";
pPeiDianGuiComponent->setPos(100, 100);
pBatteryChargeGraphicsScene->addItem(pPeiDianGuiComponent);
...... // 其它代碼略
其中ui->graphicsView為QGraphicsView類對象,第13行竟然耗時6376毫秒,如下:
最要命的是程序一起來就需要加載QGraphicsSvgItem對象上百個,那就更慢了,十分影響用戶體驗。
2. 問題解決
用Adobe Photoshop打開svg圖片,選擇“文件->導(dǎo)出->導(dǎo)出為...”,如下:
在右側(cè)“重新采樣”下拉框中選擇“兩次線性”,然后單擊右下角“導(dǎo)出”按鈕,此時原來426KB的svg圖片變?yōu)榱?0KB,然后改為加載此10KB的svg圖片,效率提升很多,耗時如下:文章來源:http://www.zghlxwxcb.cn/news/detail-827315.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-827315.html
到了這里,關(guān)于svg圖片構(gòu)造QGraphicsSvgItem對象耗時很長的問題解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!