Add an example to the documentation of QImage::scanLine()

I couldn't find any examples in Qt's documentation of this when I was
trying to use it in a project.

Pick-to: 5.15 5.12
Change-Id: Ic7b7b71f219b2c1012829980866940b9a77bd11f
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
This commit is contained in:
Mitch Curtis 2020-09-28 13:06:20 +02:00
parent 418389c3ed
commit 98d65f2ff4
2 changed files with 15 additions and 0 deletions

View File

@ -99,6 +99,17 @@ static const char * const start_xpm[] = {
};
//! [2]
//! [scanLine]
for (int y = 0; y < image.height(); ++y) {
QRgb *line = reinterpret_cast<QRgb*>(image.scanLine(y));
for (int x = 0; x < image.width(); ++x) {
QRgb &rgb = line[x];
rgb = qRgba(qRed(rgb), qGreen(0), qBlue(rgb), qAlpha(rgb));
}
}
//! [scanLine]
Q_UNUSED(start_xpm);
} // wrapper1
} // src_gui_image_qimage

View File

@ -1546,6 +1546,10 @@ void QImage::setColor(int i, QRgb c)
it follows the native alignment of 64-bit integers (64-bit for most
platforms, but notably 32-bit on i386).
For example, to remove the green component of each pixel in an image:
\snippet code/src_gui_image_qimage.cpp scanLine
\warning If you are accessing 32-bpp image data, cast the returned
pointer to \c{QRgb*} (QRgb has a 32-bit size) and use it to
read/write the pixel value. You cannot use the \c{uchar*} pointer