Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux QT
Hi,
 
I am using QIMAGE class of QT for constructing the image and using the COURIER font .
 
Printer will support 32 characters for line and i am calculating the IMAGE Height using formula total characters in file/ no of characters per line .
 
But the problem is it is giving the empty spaces after printing of the file.
 
Please help me how to resolve the issue.
 
Thank you.
 
Ashok
 

 

 

test.txt is the input file.i want all its text to correctly fit on the image.
Below is the piece of code i am using.once you execute this,you will get test2.png file.but this file has some extra spaces.
 
#include <QtGui>
#include <QDebug>
#include <QImage>
#include  <QApplication>
#include <QPainter>
#define MAX_NUM_CHAR 30
//test.txt is any text file,this is input file
#define PATH &quot;/home/narendar/test/QtTest/qtitr/test/naru/test.txt
 int main(int argc,char** argv){
 #define IMAGE_WIDTH 384
 #define FONT_HEIGHT 39
 
     QApplication app(argc,argv);
     QFile file (PATH);
     int  numLines;
     if ( file.open( QIODevice::ReadOnly ) )
     {
         QTextStream out(&amp;file);
         out.setFieldWidth(100);
         out.setFieldAlignment(QTextStream::AlignCenter);
         QString str = out.readAll();
         int  strLen = str.size();
         // Get number of lines
         numLines =  strLen / MAX_NUM_CHAR ;
         // Get image height
         int  imageHeight;
         imageHeight = FONT_HEIGHT * numLines ;
         // Construct the image with the obtained dimension
          QImage img( 384, imageHeight, QImage::Format_Mono );
          //  QImage img(100,100,QImage::Format_Mono);</pre>
img.fill(1);
         QPainter painter(&img);
         painter.drawText(QRect(0,0,IMAGE_WIDTH,imageHeight),Qt::AlignLeft | Qt::TextWrapAnywhere | Qt::TextIncludeTrailingSpaces,
             str);
    if(img.save("/home/narendar/test/QtTest/qtitr/test/naru/test2.png")){
         qDebug()<<"image saved"<<endl;
     }
         }
     app.exec();
 }
Posted 8-Aug-11 2:28am
Edited 9-Aug-11 1:11am
(no name)406.4K
v4
Comments
Richard MacCutchan at 9-Aug-11 3:55am
   
Without seeing your code it is impossible to guess what you are doing wrong.
Richard MacCutchan at 9-Aug-11 6:16am
   
This looks like an issue with the QT package and your calculations regarding text, font and image sizes. I would guess that you need to spend some time with your debugger, checking that these values are correct.
ashok1202 at 9-Aug-11 6:27am
   
Hi,
Do you find any wrong logical calculation for the algorithm ?It works fine for small files but problem mainly comes from large file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100