[solved]How to save pixmap's transformation matrix as ".txt"
-
Line 5: why the * ?
Anyway: why the matrix variable ? It's useless since you get the pixel value from the image.
Also why do you reopen the file on each iteration ?
And why the call to endl(tex) after the file has been closed ?
-
Hi,
Thanks for your response, i could get a text file which has the color information of the pixels. The code
@
QPixmap p(scn3->width(),scn3->height());
QPainter paint(&p);
scn3->render(&paint);
QImage img=p.toImage();
int width=img.width();
int height=img.height();
QFile file("/Users/venkateshpadmanabhan/Desktop/out1.txt");
file.open(QIODevice::WriteOnly);
QTextStream tex(&file);
for(int j=0;j<height;j++)
{
for (int i=0;i<width;i++)
{
int s=img.pixel(i,j);
//matrix[width][height]=qGray(img.pixel(i,j));
tex<<s;endl(tex);
//
}} file.close();
@
This works fine, but what i wanted to get is @ TransformationMatrix @ of the pixmap in a scene and convert it as a readable format like int and save it to a .txt file. But i couldn't trace how to convert the transformation matrix into Int or anything which could be accepted by @ QTextStream @
-
Again, what is the use of your matrix variable ?
Do you set that transformation somewhere ?
-
Hi,
Sorry i forgot to comment the line for the matrix, i have done that. But the problem comes when i access the transformation which i have done in
@QGraphicsPixmapItem@
In this case i try to access it by
@ QTransform mat=itm2->transform();
mat=QPixmap::trueMatrix(mat,scn3->width(),scn3->height());@But the problem is i am not sure how to set the @QTransform@ into the Text Stream for storing the transformation as @Matrix@ in ".txt" file, as i did for the color information of a pixmap
-
You have to do it by hand. Meaning create your text representation of each element of the QTransform (you can get inspiration from the qDebug() stream or QDataStream operator of QTransform)
-
Hi,
Can you suggest me some example?... I tried to find some reference idea how to implement it. But i couldn't find it any where :( I just tried@
QDataStream<<QTransform(trans);
@Is there anyway to convert the @QTransform@ into int? or any other data format to push it into QTextStream.
-
Not int, qreal or you'll loose information.
You can retrieve all the transform parameters using the mXX functions
-
Hi,
I tried to convert the QTransform into QVariant and again into qreal and pass it into QTextStream but some how it doesn't seam to work. I guess my casting is wrong ....
@QTransform mat=itm2->transform();
mat=QPixmap::trueMatrix(mat,scn3->width(),scn3->height());
QVariant qv(mat);
qreal re=qv.toReal();
QFile file("/Users/venkateshpadmanabhan/Desktop/out2.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream data(&file);
data<<re;
endl(data);
@Is this conversion method wrong?
-
Yes it is, you are expecting a matrix to be somehow transformed in one qreal value.
As I wrote before, take each parameter of the QTransform and write it to your text file.
-
Hi,
I have done as per your suggestion. But i am not sure whether it is correct. Is there any method to verify its reliability??
@
QTransform mat1=itm2->transform();
QTransform mat=QPixmap::trueMatrix(mat1,scn3->width(),scn3->height());mat.dx();
mat.dy();mat.m11(); mat.m12(); mat.m13(); mat.m21(); mat.m22(); mat.m23(); mat.m31(); mat.m32(); mat.m33(); QVariant QV(mat.dx()); QVariant QV1(mat.dy());
QVariant qv(mat.m11());
QVariant qv1(mat.m12());
QVariant qv2(mat.m13());
QVariant qv3(mat.m21());
QVariant qv4(mat.m22());
QVariant qv5(mat.m23());
QVariant qv6(mat.m31());
QVariant qv7(mat.m32());
QVariant qv8(mat.m33());
qreal re=qv.toReal();
qreal re1=qv1.toReal();
qreal re2=qv2.toReal();
qreal re3=qv3.toReal();
qreal re4=qv4.toReal();
qreal re5=qv5.toReal();
qreal re6=qv6.toReal();
qreal re7=qv7.toReal();
qreal re8=qv8.toReal();qreal RE=QV.toReal();
qreal RE1=QV1.toReal();QFile file("/Users/venkateshpadmanabhan/Desktop/out2.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream data(&file);
data<<re;
data<<re1;
data<<re2;endl(data);
data<<re3;
data<<re4;
data<<re5;endl(data);
data<<re6;
data<<re7;
data<<re8;endl(data);
data<<RE;
data<<RE1;endl(data);
file.close();@
-