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 :-)
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,
_
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...
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.
Code:
p.
setRenderHint(QPainter::Antialiasing);
//for A
image.fill(0);
p.begin(&image);
shift.setX((Ax-floor(Ax))*10);
shift.setY((Ay-floor(Ay))*10);
p.drawPixmap(shift,pixmap);
p.end();
pixmap
= QPixmap::fromImage(image.
scaledToWidth(10,Qt
::SmoothTransformation),Qt
::AutoColor);
ui->label_5->setPixmap(pixmap);
Re: Pixmap transform: translate pixmap
Quote:
Originally Posted by
DeepKling
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.
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!