Results 1 to 5 of 5

Thread: Some questions regarding image manipulation (.net -> QT)

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Some questions regarding image manipulation (.net -> QT)

    Hio, i just started with QT and I want to port some of my stuff from win to mac.

    But currently I'm a bit stuck at this point:

    I use lockbits in vb.net to get the most speed to manipulate images (as far as I know this should be the fastest way in vb.net). This is a small example how to invert an image

    Qt Code:
    1. Public Shared Function Invert_Image(ByVal doImage As Bitmap) As Bitmap
    2.  
    3. Dim imageData As BitmapData = doImage.LockBits(New Rectangle(0, 0, doImage.Width, doImage.Height), _
    4. System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb)
    5.  
    6. Dim pointer0 As IntPtr = imageData.Scan0
    7. Dim stride As Integer = imageData.Stride
    8.  
    9. Dim pixels(doImage.Width * doImage.Height - 1) As Integer
    10.  
    11. Copy(pointer0, pixels, 0, pixels.Length)
    12.  
    13. For i As Integer = 0 To pixels.Length - 1
    14. pixels(i) = (Not pixels(i) And &HFFFFFF) Or (pixels(i) And &HFF000000)
    15. Next i
    16.  
    17. Copy(pixels, 0, pointer0, pixels.Length)
    18.  
    19. doImage.UnlockBits(imageData)
    20.  
    21. Return doImage
    22. End Function
    To copy to clipboard, switch view to plain text mode 

    And this is the point where my questions starts...is there a similar way to manipulate images in QT?
    I've read the documentation for QImage but I still don't understand wether QImage got something like this lockbits or wether QT got maybe some even faster methode.

    Would some one clarify this to me maybe with some small example?

    Thx in advance
    freitag
    Last edited by freitag; 8th May 2010 at 08:14.

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

    Default Re: Some questions regarding image manipulation (.net -> QT)

    Quote Originally Posted by freitag View Post
    And this is the point where my questions starts...is there a similar way to manipulate images in QT?
    Yes, see QImage::bits().
    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
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Some questions regarding image manipulation (.net -> QT)

    Example:

    Qt Code:
    1. quint32 *p = (quint32*)image->bits();
    2. quint32 *end = (quint32*)(image->bits() + image->byteCount());
    3. uint xorbits = 0x00ffffff;
    4.  
    5. while (p < end)
    6. *p++ ^= xorbits;
    7.  
    8. QImage fixedImage(resultSize, QImage::Format_ARGB32_Premultiplied);
    9. QPainter painter(&fixedImage);
    10. painter.drawImage(imagePos(*image), *image);
    11. painter.end();
    12. ui->label->setPixmap(QPixmap::fromImage(fixedImage));
    13.  
    14. *image = fixedImage;
    To copy to clipboard, switch view to plain text mode 

    Where image is a QImage pointer.
    And ui->label is a QLabel.

  4. The following user says thank you to tbscope for this useful post:

    freitag (8th May 2010)

  5. #4
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Some questions regarding image manipulation (.net -> QT)

    Quote Originally Posted by wysota View Post
    Yes, see QImage::bits().
    thx for the answers.
    But is this the fastest way to manipulate an image using QT(i mean not using some asm inside QT)?

    i gonna test this later tbscope, thx

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

    Default Re: Some questions regarding image manipulation (.net -> QT)

    Quote Originally Posted by freitag View Post
    But is this the fastest way to manipulate an image using QT(i mean not using some asm inside QT)?
    Yes, this is the fastest way. bits() gives you direct access to pixel data.
    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.


Similar Threads

  1. Image sequence Questions...
    By Deep Thought in forum Qt Programming
    Replies: 5
    Last Post: 12th February 2016, 10:23
  2. Background manipulation of QPlainTextEdit
    By djjkotze in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2010, 13:34
  3. String manipulation methods?
    By PaladinKnight in forum Newbie
    Replies: 5
    Last Post: 16th March 2010, 23:44
  4. QString manipulation - QRegExp
    By mattia in forum Newbie
    Replies: 1
    Last Post: 18th March 2008, 11:21
  5. Replies: 3
    Last Post: 14th March 2007, 08:09

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.