diff --git a/ChangeLog.md b/ChangeLog.md index 69392e7..6ded459 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Change Log: # +- 2018.06.14 + +Added setImageWithFilePath(). + +添加用图像文件路径设置图像的方式。 + - 2018.01.30: Added resizing selected rect frame function. And now, I realize all the function I wanted in this class. But it still have some performance issues, I will optimize or rewrite it when I can. diff --git a/ImageWidget.cpp b/ImageWidget.cpp index de1fffb..74c5469 100644 --- a/ImageWidget.cpp +++ b/ImageWidget.cpp @@ -29,7 +29,7 @@ ImageWidget::~ImageWidget() qImageZoomedImage = NULL; } -void ImageWidget::setImageWithData(QImage img) +void ImageWidget::setImageWithData(QImage &img) { if(!isImageCloned) { @@ -73,6 +73,36 @@ void ImageWidget::setImageWithPointer(QImage *img) } } +void ImageWidget::setImageWithFilePath(QString &path) +{ + if(!isImageCloned) + { + qImageContainer = new QImage; + isImageCloned = true; + } + if(path.isEmpty() || path.isNull()) + { + isImageLoaded = false; + return; + } + else + { + qImageContainer->load(path); + if(qImageContainer->isNull()) + { + isImageLoaded = false; + return; + } +// qDebug() << qImageContainer->bits() << img.bits(); + isImageLoaded = true; + *qImageZoomedImage = qImageContainer->copy(); + updateZoomedImage(); + if(!isEnableRecordLastParameters) + setDefaultParameters(); + update(); + } +} + void ImageWidget::clear() { if(isImageLoaded) diff --git a/ImageWidget.h b/ImageWidget.h index e7102fd..18c21e8 100644 --- a/ImageWidget.h +++ b/ImageWidget.h @@ -26,8 +26,9 @@ class ImageWidget : ImageWidget(QWidget *parent); ~ImageWidget(); - void setImageWithData(QImage img); + void setImageWithData(QImage &img); void setImageWithPointer(QImage* img); + void setImageWithFilePath(QString &path); void setEnableOnlyShowImage(bool flag = false); // 发送点击位置坐标信号默认关闭,使用前需要开启 diff --git a/README.md b/README.md index 725d0bb..d643341 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ It's my first time to write a class and this class inherit from QWidget. It can ![](https://github.com/WangHongshuo/Readme_Images_Repository/blob/master/ImageWidget-Qt/ImageWidget-Qt_2.gif) ## Last Change: ## -- 2018.01.30: +- 2018.06.14 -Added resizing selected rect frame function. And now, I realize all the function I wanted in this class. But it still have some performance issues, I will optimize or rewrite it when I can. +Added setImageWithFilePath(). -添加了改变选中框尺寸的功能,至此该类已经达到了我所需的所有功能,但是还有一些性能上的问题。将来有能力和时间的话会进行优化或重写。 +添加用图像文件路径设置图像的方式。 - Full [Change Log](./ChangeLog.md) diff --git a/selectrect.cpp b/selectrect.cpp index 5e7e76c..5599da5 100644 --- a/selectrect.cpp +++ b/selectrect.cpp @@ -44,7 +44,7 @@ void SelectRect::receiveParentSizeChangedSignal() { ImageWidget *parentWidget = static_cast(this->parent()); this->setGeometry(0,0,parentWidget->width(),parentWidget->height()); - qDebug() << this->geometry(); +// qDebug() << this->geometry(); drawImageTopLeftPos = parentWidget->getDrawImageTopLeftPos(); update(); }