diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/doc/snippets/code/src_gui_image_qimage.cpp | 11 | ||||
-rw-r--r-- | src/gui/image/qimage.cpp | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/gui/doc/snippets/code/src_gui_image_qimage.cpp b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp index b36d12018a..cbc2aaae33 100644 --- a/src/gui/doc/snippets/code/src_gui_image_qimage.cpp +++ b/src/gui/doc/snippets/code/src_gui_image_qimage.cpp @@ -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 diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 2a16b2b845..b973b1c6a0 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -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 |