[英]Painting with rotated QPainter clips to incorrect region of QImage
[英]Determine which pixels of QImage were changed while painting on it with QPainter
我有類Paintable
,可以使用QPainter
作為參數繪制自己:
class Paintable
{
public:
virtual void paint(QPainter*) = 0;
};
這個類的實例正在一個QImage上繪制:
QImage paint(const std::vector<Paintable*>& paintables) {
QImage result;
QPainter p(&result);
for(int i = 0; i < paintables.size(); ++i) {
paintables[i]->paint(&p);
}
return result;
}
我想要實現的是,函數paint
也可以形成一個大小等於result
圖像大小的矩陣,其中每個單元格包含一個指向Paintable
的指針,該指針在result
圖像中繪制了相應的像素(類似於z-buffer)。
如果QPainter
繪制方法以某種方式讓我知道QPaintDevice
的哪些像素在最后的繪制操作期間被改變,則可以很容易地實現。 有什么想法怎么做? 我應該創建從QPaintDevice
或QPaintEngine
派生的類嗎?
我使用的是Qt 4.6.4。
謝謝。
也許不是將所有的Paintables繪制到同一個QImage上,而是將每個繪制到一個臨時的空白QImage上 - 即所有像素設置為RGBA =(0,0,0,0)的QImage。 這樣,在給定的Paintable的paint()方法返回之后,您知道QImage中現在不透明的任何像素都必須由該Paintable對象繪制。 然后,您可以根據該信息更新您自己的z-buffer數據結構,然后將QImage drawImage()轉換為單獨的“accum QImage”(假設您還需要合成結果),再次清除臨時QImage,以及必要時重復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.