Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_image_qimage.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QImage>
4#include <QRgb>
5
7void wrapper0() {
8//! [0]
9QImage image(3, 3, QImage::Format_RGB32);
10QRgb value;
11
12value = qRgb(189, 149, 39); // 0xffbd9527
13image.setPixel(1, 1, value);
14
15value = qRgb(122, 163, 39); // 0xff7aa327
16image.setPixel(0, 1, value);
17image.setPixel(1, 0, value);
18
19value = qRgb(237, 187, 51); // 0xffedba31
20image.setPixel(2, 1, value);
21//! [0]
22
23} // wrapper0
24void wrapper1() {
25
26
27//! [1]
28QImage image(3, 3, QImage::Format_Indexed8);
29QRgb value;
30
31value = qRgb(122, 163, 39); // 0xff7aa327
32image.setColor(0, value);
33
34value = qRgb(237, 187, 51); // 0xffedba31
35image.setColor(1, value);
36
37value = qRgb(189, 149, 39); // 0xffbd9527
38image.setColor(2, value);
39
40image.setPixel(0, 1, 0);
41image.setPixel(1, 0, 0);
42image.setPixel(1, 1, 2);
43image.setPixel(2, 1, 1);
44//! [1]
45
46
47//! [2]
48static const char * const start_xpm[] = {
49 "16 15 8 1",
50 "a c #cec6bd",
51 // etc.
52};
53//! [2]
54
55
56//! [scanLine]
57for (int y = 0; y < image.height(); ++y) {
58 QRgb *line = reinterpret_cast<QRgb*>(image.scanLine(y));
59 for (int x = 0; x < image.width(); ++x) {
60 QRgb &rgb = line[x];
61 rgb = qRgba(qRed(rgb), qGreen(0), qBlue(rgb), qAlpha(rgb));
62 }
63}
64//! [scanLine]
65
66Q_UNUSED(start_xpm);
67} // wrapper1
68} // src_gui_image_qimage