当前位置:网站首页>Qt supports HEIC/HEIF format images
Qt supports HEIC/HEIF format images
2022-08-01 10:02:00 【CSDN】
HEIF 格式简介(From Baidu Know)
heicThe format is for AppleiOS11A specially developed photo format.Heic是Apple iOS和macOS的文件格式,For processing images and videos.Heic是IOS 11The system replaces the original videos and photosH.264和JEP格式.HeicFormatting not only saves memory,Original image quality is also preserved.Heic格式是Apple iOS和macOS的专用格式
与JPG相比,它占用的空间更小,画质更加无损.HEIC格式照片支持iOS11及macOS High Sierra(10.13)及更新版本.但是此种格式是无法在Windows 中直接使用看图软件打开的(Windows10 RS4开始支持该格式).
HEIF和HEIC的关系?
HEIF 是图片格式,HEVC (HEVC 是编码格式(比如 H.264,H.265))进行编码的 HEIF The picture is suffixed with .heic 的图片
Qt 支持HEIF插件编译
首先声明,Qt官方并未支持heic格式图片,But there are already great gods based on itlibheiflibrary didQt的插件,This article is just to help you solve how to compile thisHeif插件
- 插件github地址
- 编译依赖:Cmake、libheif (≥ version 1.1)、Qt 5 (Core and GUI modules)
The official documentation says that compiling depends on cmake、pkg-config(个人不了解,If there is a god, please give pointers)是不准确的,容易产生误导,The real dependency isQt+libheif并且通过Cmake进行构建工程
下载编译qt-heif-image-plugin
git clone [email protected]:jakar/qt-heif-image-plugin.git
First of all, we will get an error when compiling directly
The essence here is that we can't find itpkg-config的库,So we need to solve the compilation environment configuration problem first
配置构建环境
Libheif地址
安装Libheif,github的readmehas been clearly stated in "Libheif is included in Vcpkg.",The library is already includedVcpkg中,To simplify we also need to compile it ourselvesLibheif,我们直接使用Vcpkg 进行安装Libheif
下载并安装vcpkg
> git clone https://github.com/microsoft/vcpkg
> .\vcpkg\bootstrap-vcpkg.bat
安装Libheif(以64bit column)
#指定安装(编译)64位库
> .\vcpkg\vcpkg install libheif:x64-windows
#指定安装(编译)32位库
> .\vcpkg\vcpkg install libheif:x86-windows
#默认安装32位
> .\vcpkg\vcpkg install libheif
Libheif Dependencies required during compilation are automatically downloaded(All of a sudden it's simple)编译安装之后,输出
安装pkg-config
Because it will be revised laterCmake文件,It wasn't really used laterpkg-config,此步骤可以忽略,Do your best to follow along
./vcpkg install pkgconf:x64-windows
如何让Cmake 知道我们安装的vcpkg库?
- cmake要用vcpkg下载的库
- 设置DCMAKE_TOOLCHAIN_FILE
“-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake”
我的目录是E:\Git\vcpkg
E:\Git\vcpkg\downloads\tools\cmake-3.22.2-windows\cmake-3.22.2-windows-i386\bin\cmake -B ./build_2019 -G "Visual Studio 16 2019" -A x64 -S . "-DCMAKE_TOOLCHAIN_FILE=E:\\Git\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
构建
如果下载了pkg-configCan be directly built successfully,Otherwise, it needs to be modified firstCmake文件,才可以构建VS工程
修改Cmake
cmake_minimum_required(VERSION 3.5) # lowest version tried
#新增加===
#DEBUG增加后缀
set(CMAKE_DEBUG_POSTFIX "d")
set(LIBHEIF_PATH E:\\Git\\vcpkg\\installed\\x64-windows)
###Add your own path here
set(LIBHEIF_INC_DIR ${LIBHEIF_PATH}\\include)
set(LIBHEIF_LIB_DIR ${LIBHEIF_PATH}\\lib)
#Set additional header files
include_directories(${LIBHEIF_INC_DIR})
#设置附加库目录
link_directories(${LIBHEIF_LIB_DIR})
#新增加===
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# make release build, if not specified
# (from https://blog.kitware.com/cmake-and-the-default-build-type/)
set(default_build_type "RelWithDebInfo")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Build type" FORCE)
set_property(
CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
# compiler flags
# TODO: separate GCC and Clang warnings; add more
#修改==
set(
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ -Wall \ ")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
#修改===
set(sanitizer_flags "-fsanitize=address -fsanitize=undefined")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${sanitizer_flags}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG
"${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${sanitizer_flags}")
#
# third-party libs
#
# qt
find_package(Qt5 COMPONENTS Core Gui REQUIRED)
add_definitions(-DQT_NO_KEYWORDS)
set(CMAKE_AUTOMOC ON)
# libheif
#修改==
#find_package(PkgConfig)
#pkg_check_modules(libheif REQUIRED libheif>=1.1)
set (LIB_HEIF heif libx265 libde265)
#修改==
#
# project source
#
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(sources main.cpp qheifhandler.cpp)
add_library(qheif MODULE ${sources})
#修改==
target_link_libraries(
qheif
PRIVATE
Qt5::Gui
${LIB_HEIF}
)
#修改==
#
# installation
#
# Use qmake to find plugin dir (adapted from lxqt-qtplugin)
get_target_property(
QT_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE} IMPORTED_LOCATION)
if (NOT QT_QMAKE_EXECUTABLE)
message(FATAL_ERROR "qmake is not found.")
endif ()
execute_process(
COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_PLUGINS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (QT_PLUGINS_DIR)
message(STATUS "Qt5 plugin directory: " "${QT_PLUGINS_DIR}")
else ()
message(FATAL_ERROR "Qt5 plugin directory cannot be detected.")
endif ()
# Prefix with DESTDIR if available to allow packaging
if (ENV{
DESTDIR} AND NOT ENV{
DESTDIR} STREQUAL "")
set(plugins_dir "$ENV{DESTDIR}${QT_PLUGINS_DIR}")
else ()
set(plugins_dir "${QT_PLUGINS_DIR}")
endif ()
install(
TARGETS qheif
LIBRARY DESTINATION "${plugins_dir}/imageformats")
# vim:sw=2
验证
- VS直接打开Demo工程
- Modify the example source code
#include <QApplication>
#include <QDebug>
#include <QImage>
#include<QImageReader>
#include <QLabel>
const QString path="E:\\Git\\qt-heif-image-plugin\\bird_burst.heic";
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//Output supported images
qDebug()<<QImageReader::supportedImageFormats();
const QString imgPath(path);
QImage image(imgPath);
if (!image.isNull()) {
qDebug() << "image size:" << image.size();
QLabel* label = new QLabel();
int w = 0;
int h = 0;
if (image.width() > image.height()) {
w = 1400;
h = (1.0 * image.height()) / (1.0 * image.width() * 1400);
} else {
h = 1400;
w = (1.0 * 1400 * image.height()) /(1.0 * image.width());
}
qDebug() << w << h;
const QPixmap pixmap = QPixmap::fromImage(image);
label->setPixmap(pixmap);
label->show();
label->resize(image.size());
} else {
qCritical() << "Invalid image:" << imgPath;
}
return a.exec();
}
- 编译
- 使用windeployqt打包exe
windeployqt qtheif.exe
把qheif.dllCopied to the program running directoryimageformats下
把heif.dll、libde265.dll、libx265.dllCopy to the root directory of the program running directory
运行程序,Pictures can be loaded and displayed
参考文献
vcpkg 快速入门
HEIF&HEIC
边栏推荐
猜你喜欢
随机推荐
《时代》杂志:元宇宙时代将改变世界
跨域网络资源文件下载
微信公众号授权登录后报redirect_uri参数错误的问题
Parsing MySQL Databases: "SQL Optimization" vs. "Index Optimization"
Lsky Pro 企业版手动升级、优化教程
opencv创建窗口—cv.namedWindow()
Install GBase 8 c database, the error shows "Resource, how to solve?
PDMan-国产免费通用数据库建模工具(极简,漂亮)
CTO strongly banning the use of the Calendar, that in what?
Visualization - Superset installation and deployment
【软件架构模式】MVVM模式和MVC模式区别
redis
rpm和yum
Dataset之mpg:mpg数据集的简介、下载、使用方法之详细攻略
Qt 支持HEIC/HEIF格式图片
Is the real database data of TiDB stored in kv and pd?
ASP.NET Core 6 Framework Revealing Instance Demonstration [30]: Develop REST API with Routing
CTFshow,命令执行:web33
18张图,直观理解神经网络、流形和拓扑
WLAN networking experiment of AC and thin AP