I am building a QT GUI application and use QImage for opening images. My problem is that I can't figure out how to use QImage's bit() and scanline() methods to get access at per pixel level.
I've seen this post Qt QImage pixel manipulation problems but this is only for the first pixel of each row. Is this correct or I got it all wrong?
thanks in advance
The answer did not work for me. It looks like, the data is not 32bit aligned on my system. To get the correct data, on my system i had to do this:
It may not be immediately obvious from Kaleb's post, but the following works for setting a pixel on a Format_RGB32 image.
The
scanlines
correspond to the the height of image, the columns correspond to the width of the image.According to the docs, the prototype looks like
uchar* QImage::scanline(int i)
, or a similarconst
version.But, as a commenter pointed out, because the data is dependent on the machine architecture and image, you should NOT use the
uchar *
directly. Instead, use something like the following: