Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions libimageviewer/unionimage/unionimage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -197,6 +197,9 @@ UNIONIMAGESHARED_EXPORT QString size2Human(const qlonglong bytes)
}
}

// Forward declaration for PrivateDetectImageFormat
QString PrivateDetectImageFormat(const QString &filepath);

/**
* @brief getFileFormat
* @param path
Expand All @@ -206,9 +209,15 @@ UNIONIMAGESHARED_EXPORT QString size2Human(const qlonglong bytes)
*/
UNIONIMAGESHARED_EXPORT const QString getFileFormat(const QString &path)
{
QFileInfo fi(path);
QString suffix = fi.suffix();
return suffix;
// 先尝试通过文件内容检测格式,避免修改后缀后无法正常打开图片的问题
QString format = PrivateDetectImageFormat(path);
if (format.isEmpty()) {
// 如果内容检测失败,回退到后缀名判断
QFileInfo fi(path);
QString suffix = fi.suffix();
return suffix;
}
return format;
}

UNIONIMAGESHARED_EXPORT bool canSave(const QString &path)
Expand Down
Loading