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:
parent
65fb72d302
commit
fd8132b8ae
@ -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
|
||||
|
8
src/gui/doc/snippets/image/image.pro
Normal file
8
src/gui/doc/snippets/image/image.pro
Normal file
@ -0,0 +1,8 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = image_snippets
|
||||
QT += core gui widgets
|
||||
|
||||
SOURCES = \
|
||||
image.cpp \
|
||||
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
|
||||
|
@ -10,6 +10,7 @@ contains(QT_BUILD_PARTS, tests) {
|
||||
droparea \
|
||||
dropevents \
|
||||
droprectangle \
|
||||
image \
|
||||
qfontdatabase \
|
||||
textblock-formats \
|
||||
textblock-fragments \
|
||||
|
Loading…
Reference in New Issue
Block a user