Important: Please read the Qt Code of Conduct -

Image distortion, how to?

  • Hi all

    What could be the best way using Qt classes for distort an image in the following mode?

    ! distortion)!

    Thank you

  • Hi,

    What do you mean exactly? Do you want to display a distorted representation of an image (in a widget, or in OpenGL), or do you want to load an image, apply a distortion and save the result in a new file?

  • Hi

    I want to display a distorted representation of an image in a widget.

  • Ok, IMHO the best way is to draw a textured quad in an OpenGL context (QWindow or QGLWidget depending on your Qt version and your application design) and to use a fragment shader to "distort" texture coordinates.

  • Use OpenGL is the only way to reach such result? There is no another way making it but involving standard Qt classes only?

  • Qt OpenGL classes are standard Qt classes too ;). More seriously, there is "this example": which is using QPainterPath to achieve something similar with text, but I never used it so I'm not sure it will really be what you want.

  • Well, in my understanding (that can be wrong) Qt act like a wrapper over OpenGL libraries that already have to be "supported" by the system. In my case I would to hav a code "system independent" if possible obviously (what happen if the code run in a very old system where OpenGL are not supported?). About the example you pointed I had already checked it but, basically, it make a pixet to pixel operation to create len effect. In my original question on the contrary, I would to know if Qt already provide some feature to obtain such image distortion in an easy way. If not possible I need to develop my own alghoritm (or looking for a ready made). Is just for avoid to reinvent the wheel. ;)

  • OpenGL implements shaders since version 2.0, so an old system where it is not supported should be very very old. But if you care about that, you're right, you should use QPainter functionalities but, unfortunately, AFAIK there is no easy way. Wheel isn't invented yet, you can do it ;).

Log in to reply