qt多平台使用libexif库,查看图片f编译好的库,支持win64, linux-aarch64, linux-x64
立即下载
资源介绍:
qt多平台使用libexif库,查看图片f编译好的库,支持win64, linux-aarch64, linux-x64
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "libexif/exif-data.h"
#include
#include
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, &QPushButton::clicked, [=](){
auto fileName = QFileDialog::getOpenFileName(this, "select img", ".", "img (*.jpg *.JPG)");
if (QFile(fileName).exists())
{
m_pixmap = QPixmap(fileName);
ui->label->setPixmap(m_pixmap.scaled(ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
ExifData *exifData = exif_data_new_from_file(fileName.toStdString().c_str());
QString exifInfo;
auto exif = exifData->ifd[EXIF_IFD_EXIF];
for (unsigned int i = 0; i < exif->count; ++i)
{
QString textItem;
if (exif->entries[i]->format == EXIF_FORMAT_ASCII)
{
textItem = QString("%1: %2")
.arg(exif_tag_get_name_in_ifd(exif->entries[i]->tag, EXIF_IFD_EXIF))
.arg((char*)exif->entries[i]->data);
}
else if (exif->entries[i]->format == EXIF_FORMAT_RATIONAL)
{
auto rational = exif_get_rational(exif->entries[i]->data, EXIF_BYTE_ORDER_INTEL);
textItem = QString("%1: %2/%3")
.arg(exif_tag_get_name_in_ifd(exif->entries[i]->tag, EXIF_IFD_EXIF))
.arg(rational.numerator)
.arg(rational.denominator);
}
else if (exif->entries[i]->format == EXIF_FORMAT_SRATIONAL)
{
auto rational = exif_get_srational(exif->entries[i]->data, EXIF_BYTE_ORDER_INTEL);
textItem = QString("%1: %2/%3")
.arg(exif_tag_get_name_in_ifd(exif->entries[i]->tag, EXIF_IFD_EXIF))
.arg(rational.numerator)
.arg(rational.denominator);
}
else if (exif->entries[i]->format == EXIF_FORMAT_SHORT)
{
textItem = QString("%1: %2")
.arg(exif_tag_get_name_in_ifd(exif->entries[i]->tag, EXIF_IFD_EXIF))
.arg(exif_get_short(exif->entries[i]->data, EXIF_BYTE_ORDER_INTEL));
}
else
{
textItem = QString("%1: %2")
.arg(exif_tag_get_name_in_ifd(exif->entries[i]->tag, EXIF_IFD_EXIF))
.arg((char*)exif->entries[i]->data);
}
exifInfo += textItem;
exifInfo += "\n";
}
ui->textBrowser->setText(exifInfo);
}
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
if (m_pixmap.isDetached())
ui->label->setPixmap(m_pixmap.scaled(ui->label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}