Results 1 to 6 of 6

Thread: Pixmap transform: translate pixmap

  1. #1
    Join Date
    Jan 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Pixmap transform: translate pixmap

    I want to shift a pixmap by say 0.5 px to the right and then use it for a label. Unfortunately, pixmap.transformed returns a "convenient" result, that is inconvenient to me:
    "Internally, the transformation matrix is adjusted to compensate for unwanted translation, i.e. transformed() returns the smallest pixmap containing all transformed points of the original pixmap."

    How can I shift an image by .5 px to the right? shifting a label position by .5 px doesn't work either, so I'm a bit lost here. Would be nice if there's an easy solution, I'm rather new to Qt, but I hope it's no newbie question :-)

  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: Pixmap transform: translate pixmap

    A pixel is the smallest addressable unit of the image, shifting by half a pixel either shifts by one pixel or by zero.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Pixmap transform: translate pixmap

    I guess you could create a new, slightly larger QImage. With a QPainter draw the old image after turning on anti-aliasing and translating using the QPointF version of the function. You might then get a different image that appears to have been shifted half a pixel.

    Why you would bother given the size of pixels these days...

  4. The following user says thank you to ChrisW67 for this useful post:

    DeepKling (23rd January 2015)

  5. #4
    Join Date
    Jan 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Pixmap transform: translate pixmap

    Ah, that lead to the solution, since draw doesn't accept subpixel either, I scaled up the png to 10*size, then I created a 10*larger image and pasted the huge image there, then I rescaled the image to 1/10. Thanks a lot!

    Btw., I use the label as a marker, that's why I need subpixel precision.

    Qt Code:
    1. QPixmap pixmap("CrossI.png");
    2. QImage image(100,100,QImage::Format_ARGB32_Premultiplied);
    3. p.setRenderHint(QPainter::Antialiasing);
    4. QPoint shift;
    5.  
    6. //for A
    7. image.fill(0);
    8.  
    9. p.begin(&image);
    10. shift.setX((Ax-floor(Ax))*10);
    11. shift.setY((Ay-floor(Ay))*10);
    12. p.drawPixmap(shift,pixmap);
    13. p.end();
    14. pixmap = QPixmap::fromImage(image.scaledToWidth(10,Qt::SmoothTransformation),Qt::AutoColor);
    15. ui->label_5->setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Pixmap transform: translate pixmap

    Quote Originally Posted by DeepKling View Post
    Ah, that lead to the solution, since draw doesn't accept subpixel either
    No, but translate(QPointF point) does, and then you drawPixmap() at the (translated) origin. Not certain of the result but worth a try.

  7. #6
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Pixmap transform: translate pixmap

    I would be interested in seeing the before/after images. While I'm sure you must have a valid reason for wanting to shift the image by 0.5 pixels, I'd love to see the visual difference of the result!

Similar Threads

  1. Offset of a pixmap image
    By TheIndependentAquarius in forum Newbie
    Replies: 1
    Last Post: 30th October 2013, 12:38
  2. Draw Image into Pixmap/Image
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 19th May 2010, 06:56
  3. How to transform image like warp
    By yycking in forum Qt Programming
    Replies: 2
    Last Post: 10th December 2009, 08:35
  4. Qt 3.3.8 pixmap to/from image error
    By ksierens in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 06:46
  5. Smooth pixmap transform in QGraphicsView problem
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2007, 16:47

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.