QML-更改“图像详细信息”选项卡属性中的数据

时间:2016-05-07 08:32:19

标签: qt qml

我使用Qt版本5.6.0和Windows 8.1中的qml。我想在QML中为捕获的图像设置元数据。我尝试了以下代码,在桌面上运行的程序拍摄照片并保存。在我用预览打开它并检查元数据......并没有什么特别的(没有作者密钥或cameraModel或标题,......)。

Camera {
    id: camera
    metaData.cameraModel: "lenovo"                              
    imageCapture {                              
        onImageCaptured: {
        camera.imageCapture.setMetadata(camera.metaData.title,"neda")
        camera.imageCapture.setMetadata("Title","neda")
        ...
        ...
 onImageMetadataAvailable:{
    setMetadata(key,value)
    console.log("Image Metadata Callback : "+key+" = "+value)
    setMetadata("Title","neda")
}


onClicked: {
    camera.imageCapture.setMetadata(camera.metaData.author, "neda")
    //or this code:
    camera.imageCapture.setMetadata("Author", "neda")
    //or this code:
    camera.metaData.author="neda"
    camera.imageCapture.capture()

更新 我也尝试使用QImageWriter,如下所示:

QImage image("c:/1.jpg");
QImageWriter writer("c:/11.png", "png");
writer.setText("Author", "neda");
writer.write(image);    

但是,我的尝试都没有给我任何成功(更改图像详细信息选项卡属性中的数据)。有什么想法吗?

更新: 保存图片:

#ifndef ImageSaver_H
#define ImageSaver_H
#include <QImage>
#include <QObject>
class QQuickItem;
class QString;
class ImageSaver : public QObject
{
   Q_OBJECT
   public:
        explicit ImageSaver(QObject *parent = 0);
        ImageSaver(ImageSaver const&) = delete;
        ImageSaver& operator=(ImageSaver const&) = delete;

   public slots:
   void load(QString const &path);
   void loadAndSave(QString const &path);
   void save(QString const &path) const;

private:
QImage img_;
};
#endif // ImageSaver_H


#include "ImageSaver.h"
#include <QGraphicsObject>
#include <QImageWriter>
#include <QImageIOHandler>
ImageSaver::ImageSaver(QObject *parent) :
  QObject(parent)
{
}
void ImageSaver::load(QString const &path)
{
   img_.load(path);
}
void ImageSaver::loadAndSave(QString const &path)
{
   img_.load(path);
   img_.save(path);
}
void ImageSaver::save(const QString &path) const
{
 img_.save(path);
 QImageWriter writer(path, "png");
 if (writer.supportsOption(QImageIOHandler::Description))
 {
    writer.setText("Author", "Neda");
    writer.write(img_);
 }
}

main.qml:

imageSaver.save(path);

0 个答案:

没有答案