[Qt-interest] Painting on QImage vs. QPixmap

Jesús Fernández jsfdez at gmail.com
Tue Mar 24 18:04:24 CET 2009


 From http://doc.trolltech.com/4.5/qpixmap.html:


> Qt provides four classes for handling image data: QImage<http://doc.trolltech.com/4.5/qimage.html>,
> QPixmap, QBitmap <http://doc.trolltech.com/4.5/qbitmap.html> and QPicture<http://doc.trolltech.com/4.5/qpicture.html>.
> *QImage <http://doc.trolltech.com/4.5/qimage.html> is designed and
> optimized for I/O, and for direct pixel access and manipulation, while
> QPixmap is designed and optimized for showing images on screen.* QBitmap<http://doc.trolltech.com/4.5/qbitmap.html>is only a convenience class that inherits QPixmap, ensuring a depth of 1.
> The isQBitmap <http://doc.trolltech.com/4.5/qpixmap.html#isQBitmap>()
> function returns true if a QPixmap object is really a bitmap, otherwise
> returns false. Finally, the QPicture<http://doc.trolltech.com/4.5/qpicture.html>class is a paint device that records and replays
> QPainter <http://doc.trolltech.com/4.5/qpainter.html> commands.
>
Thanks anyway ;)

2009/3/24 Brad Howes <howes at ll.mit.edu>

> I wrote a simple application to measure whether QPainting on a QImage
> was faster than doing so on a QPixmap. Interestingly, it depends on
> what operations you are doing. The source (scooby.tgz) is available at
>
>     http://idisk.mac.com/bradhowes-Public?view=web
>
> At least on my MacBook Pro running Qt 4.5 it is measurably slower to
> do indexing into a QImage (via setPixel) and then convert the QImage
> into a QPixmap for displaying vs. using QPainter to draw directly into
> a QPixmap via drawPoints (all the same color). However, if I request
> that each pixel get its own color, then QImage wins.
>
> I'd be curious if anyone can speed these cases up (the code is
> *really* simple). Here are the two drawing routines:
>
> void
> MainWindow::doImageUpdate()
> {
>     bool colorPerPixel = ui_.colorPerPixel->isChecked();
>     QRgb color( qrand() );
>     size_t count = ui_.pixelCount->value();
>     while ( count-- ) {
>        image_.setPixel( QPoint( x_++, y_ ), color );
>        if ( colorPerPixel )
>            color = QRgb( qrand() );
>
>        if ( x_ == ui_.image->width() ) {
>            x_ = 0;
>            ++y_;
>        }
>        if ( y_ == ui_.image->height() ) {
>            y_ = 0;
>        }
>     }
>
>     pixmap_ = QPixmap::fromImage( image_ );
>     ui_.image->setPixmap( pixmap_ );
> }
>
> void
> MainWindow::doPixmapUpdate()
> {
>     QPainter painter;
>     painter.begin( &pixmap_ );
>     if ( ui_.colorPerPixel->isChecked() ) {
>        size_t count = ui_.pixelCount->value();
>        while ( count-- ) {
>            QRgb color( qrand() );
>            painter.setPen( color );
>            painter.drawPoint( QPoint( x_++, y_ ) );
>            if ( x_ == ui_.image->width() ) {
>                x_ = 0;
>                ++y_;
>            }
>            if ( y_ == ui_.image->height() ) {
>                y_ = 0;
>            }
>        }
>     }
>     else {
>        std::vector<QPoint> points( ui_.pixelCount->value() );
>        for ( size_t index = 0; index < points.size(); ++index ) {
>            points[ index ] = QPoint( x_++, y_ );
>            if ( x_ == ui_.image->width() ) {
>                x_ = 0;
>                ++y_;
>            }
>            if ( y_ == ui_.image->height() ) {
>                y_ = 0;
>            }
>        }
>
>        QRgb color( qrand() );
>        painter.setPen( color );
>        painter.drawPoints( &points[ 0 ], points.size() );
>        painter.end();
>     }
>
>     ui_.image->setPixmap( pixmap_ );
> }
>
>
>
> Brad
>
> --
> Brad Howes
> Group 42
> MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
> Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420
>
>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090324/bffcc7ad/attachment.html 


More information about the Qt-interest-old mailing list