Results 1 to 4 of 4

Thread: how to rotate the image and how to maintain image aspect ration while showing.

  1. #1
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Lightbulb how to rotate the image and how to maintain image aspect ration while showing.

    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

    Qt Code:
    1. #include "qgl.h"
    2. #include "qapplication.h"
    3. #include "qimage.h"
    4. class PaintWidget : public QGLWidget{
    5. public:
    6. PaintWidget(const QString &filename,QWidget *parent=0);
    7. void paintGL();
    8. void resizeGL(int w,int h);
    9. protected:
    10. QImage data,gldata;
    11. float width,height;
    12. };
    13.  
    14. PaintWidget::PaintWidget(const QString &filename,QWidget *parent):QGLWidget(parent){
    15. data.load(filename);
    16. resize(data.size());
    17. }
    18.  
    19.  
    20. void PaintWidget::paintGL(){
    21. QImage half=data.copy(0,0,data.width()/2,data.height()/2);
    22.  
    23. gldata = QGLWidget::convertToGLFormat(half);
    24. int xsize,ysize;
    25. float xscale,yscale;
    26. xsize=width;
    27. ysize=gldata.height()*xsize / gldata.width();
    28. if(ysize > height)
    29. {
    30. ysize=height;
    31. xsize=gldata.width()*ysize / gldata.height();
    32. }
    33. xscale=(float)xsize /(float)gldata.width();
    34. yscale=(float)ysize/(float)gldata.height();
    35. glPixelZoom(xscale,yscale);
    36.  
    37. glDrawPixels(data.width(),data.height(),GL_RGBA,GL_UNSIGNED_BYTE,gldata.bits());
    38. }
    39.  
    40. void PaintWidget::resizeGL(int w, int h){
    41. glViewport(0,0,w,h);
    42. width=w;
    43. height=h;
    44. glMatrixMode(GL_PROJECTION);
    45. glLoadIdentity();
    46. glOrtho(0,w,0,h,-1,1);
    47. glMatrixMode(GL_MODELVIEW);
    48. }
    49.  
    50. int main(int argc, char** argv){
    51. QApplication app(argc,argv);
    52. PaintWidget pw(argv[1]);
    53. pw.showFullScreen();
    54. return app.exec();
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 13th March 2007 at 15:11. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to rotate the image and how to maintain image aspect ration while showing.

    Quote Originally Posted by kiransu123 View Post
    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).

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to rotate the image and how to maintain image aspect ration while showing.

    @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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to rotate the image and how to maintain image aspect ration while showing.

    And don't start three threads on the same subject.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.