diff --git a/src/Gui/ImageView.cpp b/src/Gui/ImageView.cpp index 39a2aff196..3f3cd7b60f 100644 --- a/src/Gui/ImageView.cpp +++ b/src/Gui/ImageView.cpp @@ -246,6 +246,18 @@ void ImageView::dragEnterEvent(QDragEnterEvent* event) } } +bool ImageView::isImageFormat(const QFileInfo& fileInfo) +{ + QString ext = fileInfo.suffix().toLower(); + QByteArray suffix = ext.toLatin1(); + QList supportedFormats = QImageReader::supportedImageFormats(); + auto it = std::find_if(supportedFormats.begin(), supportedFormats.end(), [suffix](const QByteArray& image) { + return (image == suffix); + }); + + return (it != supportedFormats.end()); +} + void ImageView::loadImageFromUrl(const QList& urls) { if (urls.isEmpty()) { @@ -255,7 +267,9 @@ void ImageView::loadImageFromUrl(const QList& urls) const QUrl& url = urls.first(); const QFileInfo info(url.toLocalFile()); if (info.exists() && info.isFile()) { - loadFile(info.absoluteFilePath()); + if (isImageFormat(info)) { + loadFile(info.absoluteFilePath()); + } } } diff --git a/src/Gui/ImageView.h b/src/Gui/ImageView.h index ebada88f33..95c6dced02 100644 --- a/src/Gui/ImageView.h +++ b/src/Gui/ImageView.h @@ -26,6 +26,7 @@ #include +class QFileInfo; class QLabel; class QScrollArea; class QScrollBar; @@ -82,6 +83,7 @@ private: void pasteImage(); bool canPasteImage() const; static QImage imageFromClipboard(); + static bool isImageFormat(const QFileInfo&); void loadImageFromUrl(const QList&); private: