Loading and Rotating an image with respect to one coordinate.
hi all,
I am a newbie in QT. I am using QT 4.6
My problem is that I am trying to rotate an image with one end fixed. Ex. I have an image of a rocket which I am trying to rotate. I want the base of the rocket to remain at the same position when I rotate the image.
Can you please let me know how to rotate an image with one point fixed.
thanks in advance....:)
Re: Loading and Rotating an image with respect to one coordinate.
Post the code you are using. So that we can suggest
Added after 4 minutes:
Code:
painter->translate(100, 150); // the point about which the image rotates
painter->rotate(60);
Did you used in this way???
Code:
#include <qimage.h>
#include <qwmatrix.h>
QImage myImage
("myimage.jpeg");
if( !myImage.isNull() )
{
QWMatrix m;
m.rotate( 90.0 );
myImage = myImage.xForm( m );
}
Or this way
Re: Loading and Rotating an image with respect to one coordinate.
Please use tags around the code u post.
Re: Loading and Rotating an image with respect to one coordinate.
Thanks for replying....But I am still not able to rotate the image....
I have created a resource file, where i have added image.jpg....
In the UI, I have added a label on which i have added the image using CHANGE STYLESHEET option....
now can anybody tell me how to rotate this image....
Re: Loading and Rotating an image with respect to one coordinate.
Hm,try this (for instance):
Code:
{
matrix.rotate(degrees);
pixmap=pixmap.transformed(matrix);
label->setPixmap(pixmap);
}
layout->addWidget(label);
If you want to use painter for drawing the image,take a look at the assistant,
Re: Loading and Rotating an image with respect to one coordinate.
Hmm...This code is rotating the Label, but not with respect to one fixed point....
can anybody help me rotating it with respect to one fixed point.....
Code:
{
matrix.rotate(00);
pixmap=pixmap.transformed(matrix);
this->ui->label->setPixmap(pixmap);
layout->addWidget(this->ui->label);
}
Re: Loading and Rotating an image with respect to one coordinate.
Even if there is no such a built-in method,you can write it by yourself.Point's rotation along the pivot point is a classic trigonometry problem,it's pretty straight.Even if you failed to solve it by yourself,there are a lot of resources on the net regarding it.
Re: Loading and Rotating an image with respect to one coordinate.
I think you can load the image with QImageReader to a label and call the paint event after translation followed by a rotation to a point of your interest.
Remember you need to translate the image before and after rotation to a point which you want to use as the 'center of rotation'.
Re: Loading and Rotating an image with respect to one coordinate.
hmmm .... Is there any other better alternative to keep one co-ordinate fixed, even after rotating the image......
Though I translated the image before and after rotation.....there is no change in the output..:(
it seems a bit difficult to know the X and Y parameters to be passed to translate function as i want to display the image for every two degree of rotation from 0deg to 90deg.....
I jus used translate in this way.... but no difference in output.....:(
Code:
matrix.translate(10,10);
matrix.rotate(00);
matrix.translate(20,30);
pixmap=pixmap.transformed(matrix);
this->ui->label->setPixmap(pixmap);
layout->addWidget(this->ui->label);
Re: Loading and Rotating an image with respect to one coordinate.
In your code above the translation quantity given is too small compared to the image resolution which wont produce any noticeable output, and Im confused with the rotation angle given(00).
Try this
Code:
matrix.translate(pixmap.width/2,pixmap.height);
matrix.rotate(90);
pixmap=pixmap.transformed(matrix);
this->ui->label->setPixmap(pixmap);
layout->addWidget(this->ui->label);
PS: Try and see the effect of translation and rotation, here i removed the re-translation after rotation to make the image not to go back to (0,0) as a result you will be getting a clipped one.
refer http://wiki.forum.nokia.com/index.ph..._picture_in_Qt for details.
Re: Loading and Rotating an image with respect to one coordinate.
I'd suggest taking a small step back and learning about the geometry of simple transformations like this. Rotation about an arbitrary point ALWAYS requires a translation followed by a rotation; there's no getting around it, and demands for "a better alternative" belie a fundamental ignorance of the problem that needs to be solved. No solution arrived at in this way is going to be optimal or maintainable.
Re: Loading and Rotating an image with respect to one coordinate.
Thanx a lot.... I could do it....
Re: Loading and Rotating an image with respect to one coordinate.
hi...
I have two images, which i have loaded on the QLabel through PIXMAP...
Code:
this->ui->label1->setPixmap(p1);
this->ui->label2->setPixmap(p2);
I need to place one image on the other...
But if I try to do so,the problem is one image is getting overlapped with the other...
As much as I understood, we can overcome this problem by making the pixmap background transparent....
can anybody plz tel me how can i do that and also if there are any other solution plz do suggest.....
thanks in advance....
Re: Loading and Rotating an image with respect to one coordinate.
It's not quite clear what you're trying to achieve,if you just want to place an image on a label it's fine.But if you're looking a way to display and compose the images:i don't think it's the right choice to use QLabel for it.
Take a look at the Assistant's chapter called "Paint System".Some great demos also available from the "Painting" and "Graphics View" sections.