diff --git a/src/main.cpp b/src/main.cpp index 11c93dd..89415e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) qDebug() << __FUNCTION__ << __LINE__; pOcr->openFile(QString(argv[1])); //pOcr->openImage(QImage(QSize(500, 145), QImage::Format_RGB32)); + //pOcr->openImageAndName(QImage(QSize(500, 145), QImage::Format_RGB32),"test"); return 0; } diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index d25b2d3..c51cfbb 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -273,7 +273,7 @@ void MainWidget::openImage(const QString &path) } } -void MainWidget::openImage(const QImage &img) +void MainWidget::openImage(const QImage &img,const QString & name) { createLoadingUi(); if (m_imageview) { @@ -281,7 +281,7 @@ void MainWidget::openImage(const QImage &img) QTimer::singleShot(100, [ = ] { m_imageview->fitWindow(); }); - m_imgName = ""; + m_imgName = name; } if (m_currentImg) { delete m_currentImg; diff --git a/src/mainwidget.h b/src/mainwidget.h index 7006fb5..bb1f146 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -41,8 +41,8 @@ public: void loadingUi(); - void openImage(const QString &path); - void openImage(const QImage &img); + void openImage(const QString &path ); + void openImage(const QImage &img,const QString & name=""); void loadHtml(const QString &html); void loadString(const QString &string); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 440a1b6..efd99d9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -54,8 +54,8 @@ bool MainWindow::openFile(const QString &filePaths) return true; } -bool MainWindow::openImage(const QImage &image) +bool MainWindow::openImage(const QImage &image, const QString &name) { - m_mainWidget->openImage(image); + m_mainWidget->openImage(image,name); return true; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 446db05..fdc2697 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -38,7 +38,7 @@ public: bool openFile(const QString &filePaths); - bool openImage(const QImage &image); + bool openImage(const QImage &image,const QString & name=""); private: MainWidget *m_mainWidget{nullptr}; }; diff --git a/src/ocrapplication.cpp b/src/ocrapplication.cpp index eb079c1..0fb2d57 100644 --- a/src/ocrapplication.cpp +++ b/src/ocrapplication.cpp @@ -46,3 +46,13 @@ void OcrApplication::openImage(QImage image) win->resize(800, 600); win->show(); } + +void OcrApplication::openImageAndName(QImage image, QString imageName) +{ + qDebug() << __FUNCTION__ << __LINE__ << image.size(); + MainWindow *win = new MainWindow(); + win->openImage(image,imageName); + win->resize(800, 600); + win->show(); +} + diff --git a/src/ocrapplication.h b/src/ocrapplication.h index 9aa6471..72e435d 100644 --- a/src/ocrapplication.h +++ b/src/ocrapplication.h @@ -37,6 +37,8 @@ public: Q_INVOKABLE void openImage(QImage image); + Q_INVOKABLE void openImageAndName( QImage image, QString imageName); + signals: diff --git a/src/service/dbusocr_adaptor.cpp b/src/service/dbusocr_adaptor.cpp index daee46a..85caa59 100644 --- a/src/service/dbusocr_adaptor.cpp +++ b/src/service/dbusocr_adaptor.cpp @@ -51,6 +51,17 @@ bool DbusOcrAdaptor::openFile(QString filePath) return true; } +void DbusOcrAdaptor::openImageAndName(QByteArray images,QString imageName) +{ + qDebug() << __FUNCTION__ << __LINE__; + QByteArray data = images; + QString tmp_data = QString::fromLatin1(data.data(), data.size()); + QByteArray srcData = QByteArray::fromBase64(tmp_data.toLatin1()); + data = qUncompress(srcData); + QImage image; + image.loadFromData(data); + QMetaObject::invokeMethod(parent(), "openImageAndName", Q_ARG(QImage, image), Q_ARG(QString, imageName)); +} void DbusOcrAdaptor::openImage(QByteArray images) { qDebug() << __FUNCTION__ << __LINE__; @@ -62,3 +73,4 @@ void DbusOcrAdaptor::openImage(QByteArray images) image.loadFromData(data); QMetaObject::invokeMethod(parent(), "openImage", Q_ARG(QImage, image)); } + diff --git a/src/service/dbusocr_adaptor.h b/src/service/dbusocr_adaptor.h index 409aecd..aa9a051 100644 --- a/src/service/dbusocr_adaptor.h +++ b/src/service/dbusocr_adaptor.h @@ -46,6 +46,11 @@ class DbusOcrAdaptor: public QDBusAbstractAdaptor " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" @@ -58,6 +63,7 @@ public: public Q_SLOTS: // METHODS void openImage(QByteArray images); + void openImageAndName(QByteArray images,QString imageName); bool openFile(QString filePath); diff --git a/src/service/ocrinterface.h b/src/service/ocrinterface.h index d6fbdf8..14a0859 100644 --- a/src/service/ocrinterface.h +++ b/src/service/ocrinterface.h @@ -81,6 +81,25 @@ public Q_SLOTS: // METHODS return call(QStringLiteral("openImage"), QVariant::fromValue(data)); } + /* + * @bref:openImages + * @param: image 图片 + * @param: imageName 图片名称 + * @return: QDBusPendingReply + * @note: + */ + inline QDBusPendingReply<> openImageAndName(const QImage &image,const QString &imageName) + { + qDebug() << __FUNCTION__; + QByteArray data; + QBuffer buf(&data); + if (image.save(&buf, "PNG")) { + data = qCompress(data, 9); + data = data.toBase64(); + } + return call(QStringLiteral("openImage"), QVariant::fromValue(data),imageName); + } + Q_SIGNALS: // SIGNALS };