You are not logged in.

Stiander

Beginner

  • "Stiander" is male
  • "Stiander" started this thread

Posts: 41

Location: Horten

Occupation: CEO

  • Send private message

1

Monday, October 10th 2011, 7:38am

QPainter composition

Hi,

I'm having trouble compining two QPixmaps. Basically, I have 2 QPixmaps, one containing content drawn by the user, and one containing "aid" content :

QImage resultImage(_clipBuffer.size(), QImage::Format_ARGB32_Premultiplied);
QImage sourceImage(_clipBuffer.size(), QImage::Format_ARGB32_Premultiplied);
QImage targetImage(_clipBuffer.size(), QImage::Format_ARGB32_Premultiplied);

// draw the content in the rectangular selection of the _buffer into the sourceImage
QPainter sourcePainter(&sourceImage);
sourcePainter.drawPixmap(targetRect,_buffer, rectangularSelection);
sourcePainter.end();

// draw the content of the clipmap into the targetImage
QPainter targetPainter(&targetImage);
targetPainter.drawPixmap(targetRect,_clipBuffer, targetRect);
targetPainter.end();

// initialize a painter that will paint on the result image the composition of source and target
QPainter resultPainter(&resultImage);

resultPainter.setCompositionMode(QPainter::CompositionMode_Source);
resultPainter.fillRect(targetRect, Qt::transparent);

resultPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
resultPainter.drawImage(targetRect , targetImage, targetRect);

resultPainter.setCompositionMode(compositionMode);
resultPainter.drawImage(targetRect , sourceImage, targetRect);

resultPainter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
resultPainter.fillRect(targetRect, Qt::white);

resultPainter.end();

QPainter painter(&_buffer);
painter.drawImage(rectangularSelection,resultImage,targetRect);
painter.end();

I can't get it to work. The target content is simply drawn on top of the source content without getting modified. I've tested with most of the composition modes. If anyone could give me an example of working composition code, it would help. The examples in the documentation is not getting me anywhere.

This post has been edited 3 times, last edit by "Stiander" (Oct 11th 2011, 9:01am)


Stiander

Beginner

  • "Stiander" is male
  • "Stiander" started this thread

Posts: 41

Location: Horten

Occupation: CEO

  • Send private message

2

Tuesday, October 11th 2011, 8:57am

Added a picture that illustrates the problem
Stiander has attached the following file: