0
votes

I am using Qt5.6, I have developed several widgets that render the content to an off-screen bitmap then copy the final image to the visible area.

I have an area on the visible display that shows a video feed, I want to copy the images over the video without overwriting the background and avoiding flicker.

I am currently creating the off-screen image using a 'QPixmap', I then create a painter using the Pixmap and draw as to the off-screen image. When the image is ready I then call the 'toImage' function to return a 'QImage' and then copy this to the visible display.

A lot of the widget contains lines and circles, a lot of which are not filled.

I've seen other posts not using a QPixmap, just using a 'QImage', should I be using a 'QPixmap' at all?

Question is how to copy the image from the off-screen area to the visible area without overwriting the background?

1

1 Answers

2
votes

The key to transparency is that the overlay image has got an alpha channel. QPixmap uses the graphics format of the underlying graphics system which should include an alpha channel. For QImage, the format can be explicitly specified and it should be QImage::Format_ARGB32_Premultiplied, see [1]: http://doc.qt.io/qt-5/qimage.html#Format-enum

To get a a fully transparent QImage/QPixmap in the first place, call QPixmap/QImage::fill(QColor(0, 0, 0, 0)); before creating the QPainter. The 4th parameter is the alpha channel which is 255 (full opacity) by default).

Unfortunately I can't give advice whether QPixmap or QImage is faster for your setup.

Provided the compositing operation with the videofeed considers the alpha-channel, this should solve your problem.