Results 1 to 4 of 4

Thread: Problems mapping an image file into QByteArray

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Problems mapping an image file into QByteArray

    Hi, I am modifying the QPrinter engine for the generation of Pdf because I want to include the original image file in the PDF and not a re-compressed copy of the image. The image written in a PDF is saved in a QByteArray compressed. The original code is the following:
    Qt Code:
    1. QBuffer buffer(&imageData);
    2. QImageWriter writer(&buffer, "jpeg");
    3. writer.setQuality(94);
    4. writer.write(img);
    To copy to clipboard, switch view to plain text mode 
    where "img" is the QImage to write on the PDF doc and "imageData" is the QByteArray that will be fisically written in the PDF doc calling to "writeImage". Well, I want to change the code above with the following:
    Qt Code:
    1. QFile fitxerImatge(pathImatge);
    2. imageData = fitxerImatge.readAll();
    To copy to clipboard, switch view to plain text mode 
    where "pathImatge" is the path to the original image file. The problem is that no images are written in the PDF doc with the second code and when I openit with Adobe Acrobat Reader it says that "There isn't enough data for the image". I've checked that the path is correct and, moreover, the original image file contains a JPEG image created with Qt. So, I don't know where's the problem. Could you suggest me something, please?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems mapping an image file into QByteArray

    Maybe you need to open() the file first?

  3. The following user says thank you to wysota for this useful post:

    Dark_Tower (12th December 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems mapping an image file into QByteArray

    What a mistake Thanks a lot again wysota. Finally it runs and I'm happy because i have improved some Qt code Man, I'm going to build you a statue in my town

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems mapping an image file into QByteArray

    Quote Originally Posted by Dark_Tower View Post
    Man, I'm going to build you a statue in my town
    Send me a photo when you do. And don't forget pointy ears, I seem to have them since last week.

Similar Threads

  1. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  2. How to display a QByteArray as an Image ?
    By probine in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 13:45
  3. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.