[Qt-interest] drawImage with monochrome QImage with color transfer (vs QGraphicsScene)

Samuel Rødal samuel.rodal at nokia.com
Wed Apr 7 09:15:13 CEST 2010


ext Glenn Hughes wrote:
> Hey,
> 
> I'm transitioning some code from the Mac, and I'm trying to figure out 
> how to get a particular graphical effect.
> 
> Currently we make our own Bitmap, draw directly into the memory for 
> speed, then use CopyBits to move the Bitmap memory on screen.
> In the process, the foreground color is used to colorize the one-bit image.
> So, while the image we make in memory is black and white, it can be any 
> color we wish by the time the user sees it.
> What's the best way to do something like this with QPainter?
> It seems like using a QImage and then getting at the raw buffer with 
> bits() can replicate the first part of what we do...
> but I can't figure out how to colorize it with QPainter::drawImage.
> Any ideas?
> 
> Taking a step back, is there a better way to accomplish this sort of 
> thing? The data we're drawing is pretty random. If I make paths from it, 
> they're going to be quite complicated. This is something that needs to 
> be as high performance as possible because we have to draw a lot of this 
> stuff in a scrolling pane.  (Imagine large numbers of EKG paths that may 
> be many hours in duration that need to quickly scroll.)
> 
> Would I be better off adding paths to a QGraphicsScene?
> 
> Thanks and best wishes
> Glenn

painter.setPen(Qt::red);
painter.drawPixmap(0, 0, QBitmap::fromImage(image));

QBitmaps are filled with the pen color. It might be faster to generate 
the image in Format_ARGB32_Premultiplied to begin with and draw it as is 
though (less bit manipulation overhead).

--
Samuel




More information about the Qt-interest-old mailing list