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
#define PATH "/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(&file);
out.setFieldWidth(100);
out.setFieldAlignment(QTextStream::AlignCenter);
QString str = out.readAll();
int strLen = str.size();
numLines = strLen / MAX_NUM_CHAR ;
int imageHeight;
imageHeight = FONT_HEIGHT * numLines ;
QImage img( 384, imageHeight, QImage::Format_Mono );
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();
}