이것이 내가하는 방법이라고 생각합니다. 나는 이것이 당신의 의견에 따라 좋을 것 같아요.
QPainter를 사용하여 원본에서 반영된 반사 이미지를 만들고 QPainter를 다시 사용하여 두 이미지를 병합합니다. 이 결과 이미지는 QGraphicsPixmapItem을 사용하여 표시된 이미지입니다. 아래 코드에서 이미지의 반영된 미러 버전을 만들었습니다. 매개 변수를 조정하고 병합하면됩니다.
#include <QApplication>
#include <QLabel>
#include <QPixmap>
#include <QPainter>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Just to show the original image.
QLabel label;
QImage original(<place_an_image_path_here>);
label.setPixmap(QPixmap::fromImage(original));
label.show();
// Create the gradient that will be placed over the image.
QPoint start(0, 0);
QPoint end(0, original.height());
QLinearGradient gradient(start, end);
gradient.setColorAt(0.0, Qt::white);
gradient.setColorAt(0.5, Qt::black);
// Create the mask to be used on the mirrored image.
QImage mask(original.size(), original.format());
QPainter painter(&mask);
// You may want to add additional opacity according
// to the sample image shown.
painter.setOpacity(0.8);
painter.fillRect(original.rect(), gradient);
painter.end();
// Create the mirrored reflection.
QImage reflection = original.mirrored();
reflection.setAlphaChannel(mask);
// Just to show the result.
QLabel labelReflection;
labelReflection.setPixmap(QPixmap::fromImage(reflection));
labelReflection.show();
return a.exec();
}
당신은 QGraphicsPixmapItem의 결과 이미지 (두의 병합의 결과를)로드 할 수 있습니다 그리고 당신은 당신이 필요로하는 모든 변환을 적용하는 갈 수 있습니다.
편집 : 제공되는 이미지가 나타내는 것처럼 추가 불투명도를 설정하는 것을 잊어 버릴 수 있습니다. 시도하지는 않았지만 QPixmaps를 사용하여 동일한 작업을 수행 할 수도 있습니다. 이렇게하면 성능이 향상되거나 사용중인 플랫폼 및 페인트 엔진에 따라 그림이 빨라질 수도 있습니다.
EDIT2 : (내가 확인하기 위해 시도했지만 아무것도 기록되지 않았다,이 이미지는 일부 저작권 또는 유사한받지 않는 희망)
내 첫번째 생각 : 요청으로이 내 테스트 코드의 출력 QGraphicsItemGroup에서 상속받은 새 클래스를 만듭니다. 생성자는 입력으로 pixmap을가집니다. 두 개의 QGraphicsPixmapItem을 만듭니다. QGraphicsItemGroup에 둘 다 추가하십시오. 두 번째 그래픽 항목을 "미러"(구현에 따라 ...)로 배열하십시오. –