简体   繁体   English

使用QPainter在QPixmap上绘制图形

[英]Plotting a graph over a QPixmap using QPainter

I need to plot a real time graph keeping the background an image. 我需要绘制一个实时图形,使背景图像保持不变。 Let's say I am plotting the graph with a red color. 假设我正在用红色绘制图形。

But the logic I use for plotting is drawing small lines using painter.drawline, where painter is a pixmap painter. 但是我用于绘制的逻辑是使用painter.drawline绘制细线,其中painter是一个pixmap painter。 Then I am constantly drawing this pixmap using a painter to parent widget on a timer timeout() event. 然后,我不断使用一个画家在计时器timeout()事件上绘制此像素图作为父小部件。 So it appears the updated Image (which is the graph) gets plotted in the Gui. 这样看来,更新的图像(即图形)在Gui中绘制了。

The pixmap is black in background and plotting pen color is red, So when it reaches the end of screen width, I have to start drawing the graph from position 0, but from the second cycle onwards I have to fill the previously drawn pixels (not the entire pixmap, just a rect of width few pixels and height, height of pixmap) with black color. 像素图在背景中为黑色,并且绘图笔的颜色为红色,因此,当到达屏幕宽度的末端时,我必须从位置0开始绘制图形,但是从第二个循环开始,我必须填充先前绘制的像素(不是整个像素图,宽度仅为几个像素,高度,像素图的高度)为黑色。

But now I need to keep a background image, and draw a graph over it. 但是现在我需要保留背景图像,并在其上绘制图形。 So the fillling with black color doesn't do, as I have to keep a background an image. 因此,用黑色填充不起作用,因为我必须将背景图像保留下来。 So how can I plot a graph over an image like aforementioned? 那么,如何在上述图像上绘制图形呢?

Is there any way to blend two images such that the pixels only having a particular color (red) in source image is blended/replaced with corresponding pixels in destination image? 是否有任何方法可以混合两个图像,以便将源图像中仅具有特定颜色(红色)的像素与目标图像中的相应像素进行混合/替换?

Keep previously drawed Ys in memory than fill exactly the same pixels by corresponding background. 将先前绘制的Y保留在内存中,然后用相应的背景完全填充相同的像素。 It's faster and much more reliable. 它更快,更可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM