PDA

View Full Version : Problems mapping an image file into QByteArray



Dark_Tower
12th December 2006, 07:57
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:

QBuffer buffer(&imageData);
QImageWriter writer(&buffer, "jpeg");
writer.setQuality(94);
writer.write(img);
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:

QFile fitxerImatge(pathImatge);
imageData = fitxerImatge.readAll();
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?

wysota
12th December 2006, 10:48
Maybe you need to open() the file first?

Dark_Tower
12th December 2006, 12:35
What a mistake :eek: 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 ;)

wysota
12th December 2006, 21:23
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.