Results 1 to 6 of 6

Thread: QImage to text file

  1. #1
    Join Date
    Sep 2009
    Location
    phoenix, AZ
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default QImage to text file

    Guys,

    quick question, is that possible to dump a Qimage in a text file so l can same numerical data and images in a same text file ?

    thanks,

    Michael

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage to text file

    You can always write an image to a file. It depends on what format you want to write.
    text files contains text. Applications will open text files as text files.
    If you want to embedd image with text, you can save in doc or pdf format. Qt provides support to write in pdf format. You can opt for that.

    Other easy way -
    Save QImage as image file...open in paint , copy image and paste in MS Word.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QImage to text file

    I think the OP wants to save an image and some related, human readable data in the same text file and have the image recoverable even if the user edits the extra data. In this case base64, a start/end marker pair, and a big warning that the user should not edit between the markers might be the best bet.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QImage to text file

    Just a note that base64 is not efficient for binary data.
    I would go for a gzipped folder containing the images as jpg or png and some xml or other config files.
    Last edited by tbscope; 2nd August 2010 at 13:51. Reason: typo

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage to text file

    you can save your image in QByteArray and then save a QByteArray into file.
    take a look at QImage::save.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Sep 2009
    Location
    phoenix, AZ
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: QImage to text file

    thanks guy, got it to work.
    Save to text file:
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    QTextStream out(&file);

    Image_snapshot.save(&buffer, "PNG");
    out << buffer.data().toHex();


    load from file:
    if(line.contains("#BEGIN_Image"))
    {
    line = in.readLine();
    ba.clear();
    while (!line.contains("#END_Image")) {
    line = in.readLine();
    QTextStream(&ba) << line;
    }
    QByteArray readCompressed = QByteArray::fromHex(Buffer.toAscii());
    if(!WebCam_snapshot.loadFromData(readCompressed))
    qDebug() << "fail to load Qbytrearray";

    //test image
    if(!WebCam_snapshot.save("test.bmp"))
    qDebug() << "fail to save image from Qbytrearray";

    }

Similar Threads

  1. Unable to load gif file in QImage.
    By spsingh in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2010, 09:08
  2. Gif plugin loaded but QImage cant read gif file.
    By spsingh in forum Installation and Deployment
    Replies: 0
    Last Post: 30th July 2010, 13:26
  3. Replies: 3
    Last Post: 3rd May 2009, 08:58
  4. QImage, get file format
    By greenvirag in forum Qt Programming
    Replies: 6
    Last Post: 29th December 2008, 13:13
  5. Replies: 1
    Last Post: 3rd September 2008, 14:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.