diff options
Diffstat (limited to 'src/gui/doc/snippets/image')
-rw-r--r-- | src/gui/doc/snippets/image/image.cpp | 78 | ||||
-rw-r--r-- | src/gui/doc/snippets/image/image.pro | 8 | ||||
-rw-r--r-- | src/gui/doc/snippets/image/supportedformat.cpp | 7 |
3 files changed, 35 insertions, 58 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 diff --git a/src/gui/doc/snippets/image/image.pro b/src/gui/doc/snippets/image/image.pro new file mode 100644 index 00000000000..c9b5e30cd18 --- /dev/null +++ b/src/gui/doc/snippets/image/image.pro @@ -0,0 +1,8 @@ +TEMPLATE = lib +TARGET = image_snippets +QT += core gui widgets + +SOURCES = \ + image.cpp \ + supportedformat.cpp + diff --git a/src/gui/doc/snippets/image/supportedformat.cpp b/src/gui/doc/snippets/image/supportedformat.cpp index a537d2cdc38..c6a9779ac94 100644 --- a/src/gui/doc/snippets/image/supportedformat.cpp +++ b/src/gui/doc/snippets/image/supportedformat.cpp @@ -50,13 +50,12 @@ #include <QtGui> -int main(int argv, char **args) -{ +void wrapper() { //! [0] QImageWriter writer; writer.setFormat("png"); if (writer.supportsOption(QImageIOHandler::Description)) qDebug() << "Png supports embedded text"; //! [0] - return 0; -} + +} // wrapper |