[Interest] QImage transformed() background color

Jason H jhihn at gmx.com
Mon May 7 21:56:40 CEST 2018


I'm rotating some images by non-90 degree amounts, but when I do, the image gets filled with a color value (black) for pixels where there is no image data after rotation, but are in the output image, which causes a problem with later analysis because it trips edge detection. It would be nice to be able to control the fill color, or better yet, not have any fill as a result of the rotate, and just use want's in the image. Ideally, I'd like to pass it a fillColor (Qt::transparent) so that I can just look at the alpha channel and ignore pixels with a 0 alpha. How can I accomplish that if I can't select the color?

I don't know that it's possible to select the rotated rectangle out and draw it on a transparent image with a QPainter?


QImage rotate(const QImage &image, double degrees){
	if (degrees > 0.01 || degrees < -0.01) {
		QTransform tx;
		QPoint center = image.rect().center();
		tx.translate(center.x(), center.y());
		tx.rotate(degrees);
		return image.transformed(tx, Qt::SmoothTransformation);
	} else {
		return image;
	}
}



More information about the Interest mailing list