Save coordinate references on image QML
-
-
Hi all,
i desire to put on an image some coordinate references by mouse clicked. But for me it's important to save these references (one or more) in that image because i need to show other widgets in those references in another app. How i can do?@Polly
if it's just for your application, why not simply wrap your image into an customclass/struct? Or did i misunderstood something?struct MyImage { QPoint coordinates; QImage image; }
-
Yes, but i would save this image in a file so another app recalls it and this app put in this image some objects . I want to create a simple app for turism when you see an image and some visual reference where you click it and you see another window where you find more informations about that detail.
So i searched a way to put that references in that image. -
Yes, but i would save this image in a file so another app recalls it and this app put in this image some objects . I want to create a simple app for turism when you see an image and some visual reference where you click it and you see another window where you find more informations about that detail.
So i searched a way to put that references in that image. -
Yes, but i would save this image in a file so another app recalls it and this app put in this image some objects . I want to create a simple app for turism when you see an image and some visual reference where you click it and you see another window where you find more informations about that detail.
So i searched a way to put that references in that image.@Polly
please give this (completley untested) code a try:class MyImage : public QObject { Q_OBJECT public: explicit MyImage(QObject *parent = 0); friend inline QDataStream &operator<<(QDataStream &ds, const MyImage &obj) { // write image QImageWriter imgWriter( ds.device(), "PNG" ); if( !img.write(img.m_Image) ) { ds.setStatus( QDataStream::WriteFailed ); return ds; } // write coordinates ds << img.m_Coordinates; return ds; } friend inline QDataStream &operator>>(QDataStream &ds, MyImage &obj) { QImage image; QPoint coordinates; // read image QImageReader imgReader( ds.device() ); if( reader.read(&image) ) img.m_Image = image; else { ds.setStatus( QDataStream::ReadCorruptData ); return ds; } // read coordinates ds >> coordinates; if( ds.status() == QDataStream::Ok ) img.m_Coordinates = coordinates; return ds; } protected: QImage m_Image; QPoint m_Coordinates; };
IIRC it's ok to append data to image binaries without corrupting the image itself. Might depend on the used image format though.
then you can read/write your custom class this way:
MyImage img; QFile file("myimage.png"); if( file.open(QIODevice::ReadOnly) ) { QDataStream in(&file); in >> img; }
As i said the code is completely untested and honestly i do not even know if it compiles.