You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

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: