PDA

View Full Version : Some questions regarding image manipulation (.net -> QT)



freitag
8th May 2010, 08:08
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


Public Shared Function Invert_Image(ByVal doImage As Bitmap) As Bitmap

Dim imageData As BitmapData = doImage.LockBits(New Rectangle(0, 0, doImage.Width, doImage.Height), _
System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb)

Dim pointer0 As IntPtr = imageData.Scan0
Dim stride As Integer = imageData.Stride

Dim pixels(doImage.Width * doImage.Height - 1) As Integer

Copy(pointer0, pixels, 0, pixels.Length)

For i As Integer = 0 To pixels.Length - 1
pixels(i) = (Not pixels(i) And &HFFFFFF) Or (pixels(i) And &HFF000000)
Next i

Copy(pixels, 0, pointer0, pixels.Length)

doImage.UnlockBits(imageData)

Return doImage
End Function


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

wysota
8th May 2010, 09:06
And this is the point where my questions starts...is there a similar way to manipulate images in QT?
Yes, see QImage::bits().

tbscope
8th May 2010, 09:19
Example:


quint32 *p = (quint32*)image->bits();
quint32 *end = (quint32*)(image->bits() + image->byteCount());
uint xorbits = 0x00ffffff;

while (p < end)
*p++ ^= xorbits;

QImage fixedImage(resultSize, QImage::Format_ARGB32_Premultiplied);
QPainter painter(&fixedImage);
painter.drawImage(imagePos(*image), *image);
painter.end();
ui->label->setPixmap(QPixmap::fromImage(fixedImage));

*image = fixedImage;

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

freitag
8th May 2010, 09:26
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

wysota
8th May 2010, 11:40
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.