diff options
Diffstat (limited to 'src/gui/doc/snippets/image/image.cpp')
-rw-r--r-- | src/gui/doc/snippets/image/image.cpp | 78 |
1 files changed, 24 insertions, 54 deletions
diff --git a/src/gui/doc/snippets/image/image.cpp b/src/gui/doc/snippets/image/image.cpp index c3b9abc364f..3f2e7371e0e 100644 --- a/src/gui/doc/snippets/image/image.cpp +++ b/src/gui/doc/snippets/image/image.cpp @@ -47,68 +47,38 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - #include <QtGui> +namespace image { +void wrapper0() { -int main() -{ - int x, y; - { - // BIT ACCESS - QImage image; - // sets bit at (x, y) to 1 - if (image.format() == QImage::Format_MonoLSB) - image.scanLine(y)[x >> 3] |= 1 << (x & 7); - else - image.scanLine(y)[x >> 3] |= 1 << (7 - (x & 7)); - } +//! [0] +QImage image; +QByteArray ba; +QBuffer buffer(&ba); +buffer.open(QIODevice::WriteOnly); +image.save(&buffer, "PNG"); // writes image into ba in PNG format +//! [0] - { - // 8-BIT ACCESS - QImage image; - // set entry 19 in the color table to yellow - image.setColor(19, qRgb(255, 255, 0)); +} // wrapper0 - // set 8 bit pixel at (x,y) to value yellow (in color table) - image.scanLine(y)[x] = 19; - } - { - // 32-BIT - QImage image; - // sets 32 bit pixel at (x,y) to yellow. - uint *ptr = reinterpret_cast<uint *>(image.scanLine(y)) + x; - *ptr = qRgb(255, 255, 0); - } +void wrapper1() { - { - // SAVE -//! [0] - QImage image; - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); // writes image into ba in PNG format -//! [0] - } - - { - // PIX SAVE //! [1] - QPixmap pixmap; - QByteArray bytes; - QBuffer buffer(&bytes); - buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format +QPixmap pixmap; +QByteArray bytes; +QBuffer buffer(&bytes); +buffer.open(QIODevice::WriteOnly); +pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format //! [1] - } - { - // MASK + //! [2] - QPixmap alpha("image-with-alpha.png"); - QPixmap alphacopy = alpha; - alphacopy.setMask(alphacopy.mask()); +QPixmap alpha("image-with-alpha.png"); +QPixmap alphacopy = alpha; +alphacopy.setMask(alphacopy.mask()); //! [2] - } -} + +} // wrapper1 + +} // image |