Results 1 to 5 of 5

Thread: rotate a bitmap image

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default rotate a bitmap image

    I do not know how to rotate bitmap BGR image of size 800 * 600 * 3 by 90 degrees. If it was an image with a header, the solution would be:
    Qt Code:
    1. QImage srcImg(":/icon.png");
    2. QPoint center = srcImg.rect().center();
    3. QMatrix matrix;
    4. matrix.translate(center.x(), center.y());
    5. matrix.rotate(90);
    6. QImage dstImg = srcImge.transformed(matrix);
    7. QPixmap dstPix = QPixmap::fromImage(dstImg);
    To copy to clipboard, switch view to plain text mode 

    I read the whole image in a 800 * 600 * 3 image. Next, before I render it to the screen, I need to rotate it by 90 degrees.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rotate a bitmap image

    What do you mean if it were an image with a header?

    Cheers,
    _

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: rotate a bitmap image

    Quote Originally Posted by anda_skoa View Post
    What do you mean if it were an image with a header?

    Cheers,
    _
    if it is PNG or JPEG we can set it the QByteArray to a pixmap or QImage like:
    image->loadFromData(bytes, "PNG");
    but when it is raw data of 800 by 600 by 3, it has no header, it is not PNG or of any type anymore. I wonder how I can rotate the image by 90 degree in this case!

    Cheers,

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: rotate a bitmap image

    But you still know how to access the pixel(i,j), and how to display the data ? What is the pixel data layout now ?
    Another thing, how do you display the data ? If you need the rotation only for display, and you are using opengl, you can rotate it by simple glRotate(...) before pixmap rendering code.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rotate a bitmap image

    Quote Originally Posted by saman_artorious View Post
    but when it is raw data of 800 by 600 by 3, it has no header, it is not PNG or of any type anymore. I wonder how I can rotate the image by 90 degree in this case!
    At the time when transformed() is called with the rotation matrix, there is just QImage, so it always works the same way.
    QImage works on pixel data, not on whatever source format. The source format is only important for getting the pixel data into the QImage instance.
    Since you are asking about the rotation step, which is after loading, I assume you have the loading covered.

    So the answer to your question is: create a rotation matrix, call QImage::transformed()

    Cheers,
    _

Similar Threads

  1. rotate an image
    By saman_artorious in forum Qt Programming
    Replies: 9
    Last Post: 29th May 2013, 18:05
  2. convert 16 bit raw data to 24bit bitmap image
    By bibhukalyana in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2011, 18:58
  3. Qt form to bitmap image .. How to
    By Ratheendrans in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2010, 13:22
  4. how to rotate an image...
    By sh123 in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2009, 14:59
  5. Replies: 3
    Last Post: 14th March 2007, 08:09

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.