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
Code:
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
Re: Some questions regarding image manipulation (.net -> QT)
Quote:
Originally Posted by
freitag
And this is the point where my questions starts...is there a similar way to manipulate images in QT?
Yes, see QImage::bits().
Re: Some questions regarding image manipulation (.net -> QT)
Example:
Code:
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);
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.
Re: Some questions regarding image manipulation (.net -> QT)
Quote:
Originally Posted by
wysota
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
Re: Some questions regarding image manipulation (.net -> QT)
Quote:
Originally Posted by
freitag
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.