Results 1 to 5 of 5

Thread: Scaling QImage ( zooming ) and drawing slowes down the performance

  1. #1
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Scaling QImage ( zooming ) and drawing slowes down the performance

    Hi all,

    I am developing small application which can edit image.That is it has Zoom and Erase functionality.

    I am facing performance issue when i zoom the image and starts erasing it.

    Zoom functionality is implemented by scaled() API of QImage and erase functionality is implemented by drawing on the scaled image with CompositionMode set to QPainter::CompositionMode_Clear.

    How MSPAINT application does the same task smoothley.

    Is there any way to improve the performance?

    Thanks in advance

    Regards,
    ~Sanjay

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scaling QImage ( zooming ) and drawing slowes down the performance

    We'd have to see the exact code. I'm assuming you are converting between QImage and QPixmap all the time and this is slow.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scaling QImage ( zooming ) and drawing slowes down the performance

    Very true.

    I am converting it from QPixmap to QImage.And then erased image using QPainter.
    After done erasing converting to QPixmap again.

    like this :

    Qt Code:
    1. QImage imgPixmap(m_imgViewer->pixmap()->toImage());
    2.  
    3. QPainter painter(&imgPixmap);
    4. painter.setCompositionMode(QPainter::CompositionMode_Clear);
    5. QPen pen;
    6. pen.setCapStyle(Qt::RoundCap);
    7. pen.setWidth(m_nEraserSize);
    8. painter.setPen(pen);
    9. painter.drawPoint(ptPos);
    10. painter.end();
    11.  
    12. m_imgViewer->setPixmap(QPixmap::fromImage(imgPixmap)); // show the image
    13. m_imgViewer->setMinimumSize(m_imgViewer->pixmap()->size());
    To copy to clipboard, switch view to plain text mode 


    Note : m_imgViewer is a QLabel.

    Any idea how to do that.

    Regards,
    ~Sanjay
    Last edited by wysota; 8th May 2009 at 13:23. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scaling QImage ( zooming ) and drawing slowes down the performance

    How about having two pixmaps - one is the base image and the other is a mask that you will apply to the image when saving it. Then you don't have to convert the base pixmap, just operate on the upper "layer".

    A simpler solution is to paint directly on the pixmap, you don't have to convert it to QImage before doing so.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scaling QImage ( zooming ) and drawing slowes down the performance

    Very sorry.
    I am late to reply.
    yes i tried painting directly on QPixmap and it works.

    Thank you.


    regards,
    ~Sanjay

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.