PDA

View Full Version : how to rotate the image and how to maintain image aspect ration while showing.



kiransu123
13th March 2007, 01:50
hi i m kiran
i wnt to display image and also maintain 1:1 aspect ratio but i trid the some part of image is not visible is there any way to maintain that

i hav written followng prog and nw i wnt to rotate the image
wht cn i do

i wnt to handle mouse event is there any way to do that



#include "qgl.h"
#include "qapplication.h"
#include "qimage.h"
class PaintWidget : public QGLWidget{
public:
PaintWidget(const QString &filename,QWidget *parent=0);
void paintGL();
void resizeGL(int w,int h);
protected:
QImage data,gldata;
float width,height;
};

PaintWidget::PaintWidget(const QString &filename,QWidget *parent):QGLWidget(parent){
data.load(filename);
resize(data.size());
}


void PaintWidget::paintGL(){
QImage half=data.copy(0,0,data.width()/2,data.height()/2);

gldata = QGLWidget::convertToGLFormat(half);
int xsize,ysize;
float xscale,yscale;
xsize=width;
ysize=gldata.height()*xsize / gldata.width();
if(ysize > height)
{
ysize=height;
xsize=gldata.width()*ysize / gldata.height();
}
xscale=(float)xsize /(float)gldata.width();
yscale=(float)ysize/(float)gldata.height();
glPixelZoom(xscale,yscale);

glDrawPixels(data.width(),data.height(),GL_RGBA,GL _UNSIGNED_BYTE,gldata.bits());
}

void PaintWidget::resizeGL(int w, int h){
glViewport(0,0,w,h);
width=w;
height=h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1,1);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv){
QApplication app(argc,argv);
PaintWidget pw(argv[1]);
pw.showFullScreen();
return app.exec();

}

jacek
13th March 2007, 19:59
i wnt to handle mouse event is there any way to do that
Just reimplement QWidget::mouseMoveEvent() (don't forget to turn the mouse tracking on).

high_flyer
13th March 2007, 20:30
@kiransu123:
I guess you are not using your nokia to write the posts here, so PLEASE, don't use that sms shorttext, its hard to read and anoying.
Please use regular text.

wysota
14th March 2007, 08:09
And don't start three threads on the same subject.