Doc: compile image snippets

Done-with: Nico Vertriest <nico.vertriest@qt.io>
Task-number: 81486
Change-Id: I9860217a80cf94d27542d7e7836fe60fcd60897e
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
This commit is contained in:
Paul Wicking 2020-08-31 14:09:05 +02:00
parent 65fb72d302
commit fd8132b8ae
4 changed files with 39 additions and 61 deletions

View File

@ -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));
}
{
// 8-BIT ACCESS
QImage image;
// set entry 19 in the color table to yellow
image.setColor(19, qRgb(255, 255, 0));
// 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);
}
{
// SAVE
//! [0]
QImage image;
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG"); // writes image into ba in PNG format
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
//! [1]
}
} // wrapper0
void wrapper1() {
//! [1]
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

View File

@ -0,0 +1,8 @@
TEMPLATE = lib
TARGET = image_snippets
QT += core gui widgets
SOURCES = \
image.cpp \
supportedformat.cpp

View File

@ -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

View File

@ -10,6 +10,7 @@ contains(QT_BUILD_PARTS, tests) {
droparea \
dropevents \
droprectangle \
image \
qfontdatabase \
textblock-formats \
textblock-fragments \