3

ここで正しい用語を使用しているかどうかはわかりません。しかし、これは私が達成しようとしていることであり、それを達成する方法についていくつかの提案が欲しい. 境界線が見える円が欲しい。ここが難しい部分で、どうやって始めればいいのかさえわかりません。円の境界が表示され、その中心が表示されないように円を操作したい (つまり、その中に穴があり、その下に配置されているものを表示するのとほぼ同じです)。円の透明な部分の下にある画像の部分のみが表示されるように、円の下に別の画像を配置すると、円の透明な境界の外側の部分が見えなくなります。これを達成する方法についての提案。グーグルは私を助けていないようです。

4

2 に答える 2

5

画像の円形領域のマスクを解除する別の方法をお勧めします。クリップ領域 (ペイントを実行する必要がある領域) を指定できます。例えば:

[..]
QPainter painter(this);
// Sample circular area.
QRegion r(QRect(100, 100, 200, 200), QRegion::Ellipse);
painter.setClipRegion(r);
[..]
painter.drawImage(0, 0, image);
[..]

これにより、半径 200 の円の内側にある画像の部分のみが描画されます。残りのピクセルはすべて非表示になります。マウス移動イベントを処理して、この「円」をルーペのように画像上で移動できます。

アップデート

以下は、円形マスクを使用して画像を生成し、それをラベルに挿入するサンプル コードです。

QPixmap target(500, 500); // the size may vary
QPixmap source("image.png");

QPainter painter(&target);
QRegion r(QRect(100, 100, 200, 200), QRegion::Ellipse);
painter.setClipRegion(r);
painter.drawPixmap(0, 0, source);

QLabel l;
l.setPixmap(target);
l.show();
于 2013-12-11T09:34:57.760 に答える
2

You might want to have a look at the Composition Example.

In short you could draw the first image and then use one of the Composition Modes to draw the second image on top (or the other way around). Make sure to convert the images to ARGB32 before using them. To make the inner Part of the Circle transparent you can adjust the Alpha Channel accordingly.

Here is a small Example using Composition mode:

QPainter p(&imageCircle);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
p.drawImage(image);
p.end()

Here you can find the Qt Documentation of QPainter.

于 2013-12-11T07:31:38.977 に答える