Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Save coordinate references on image QML

Save coordinate references on image QML

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PollyP Offline
    PollyP Offline
    Polly
    wrote on last edited by Polly
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • PollyP Polly

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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;
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • PollyP Offline
        PollyP Offline
        Polly
        wrote on last edited by Polly
        #3

        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.

        artwawA raven-worxR 2 Replies Last reply
        0
        • PollyP Polly

          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.

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          @Polly If you just with to write/paint something over existing image you can just (having coords already in variable) use QPainter::drawText() method to draw text over the image.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          0
          • PollyP Polly

            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.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @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.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved