ViewSolutions
1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Toggle main menu visibility
Loading...
Searching...
No Matches
colorpicker.cpp
Go to the documentation of this file.
1
//#
2
//# Copyright (C) 2020-2025 QuasarApp.
3
//# Distributed under the GPLv3 software license, see the accompanying
4
//# Everyone is permitted to copy and distribute verbatim copies
5
//# of this license document, but changing it is not allowed.
6
//#
7
8
#include "
colorpicker.h
"
9
10
#include <QColor>
11
#include <QImage>
12
#include <QUrl>
13
namespace
ViewSolutions
{
14
15
ColorPicker::ColorPicker
() {
16
17
}
18
19
QColor
ColorPicker::pick
(
int
x,
int
y,
const
QImage &img)
const
{
20
return
img.pixelColor(x, y);
21
}
22
23
QColor
ColorPicker::pick
(
const
QImage &img,
int
density)
const
{
24
int
stepX = img.width() / density;
25
int
stepY = img.height() / density;
26
27
if
(!(stepX && stepY)) {
28
return
QColor::fromRgb(0);
29
}
30
31
int
A = 0,
32
R = 0,
33
G = 0,
34
B = 0;
35
36
for
(
int
x = stepX - 1; x < img.width(); x += stepX) {
37
for
(
int
y = stepY - 1; y < img.height(); y += stepY) {
38
int
pixel = img.pixel(x, y);
39
A += (pixel & 0xFF000000) >> 24;
40
R += (pixel & 0x00FF0000) >> 16;
41
G += (pixel & 0x0000FF00) >> 8;
42
B += pixel & 0x000000FF;
43
}
44
}
45
46
int
count = density * density;
47
return
QColor::fromRgba(((A / count) << 24) |
48
((R / count) << 16) |
49
((G / count) << 8) |
50
B / count);
51
}
52
53
QColor
ColorPicker::pick
(
const
QString &img)
const
{
54
if
(img.left(3).compare(
"qrc"
) == 0) {
55
return
pick
(QImage(img.right(img.size() - 3)));
56
}
57
58
if
(img.left(5).compare(
"file:"
) == 0) {
59
return
pick
(QImage(img.right(img.size() - 5)));
60
}
61
62
return
pick
(QImage(img));
63
}
64
65
}
ViewSolutions::ColorPicker::pick
QColor pick(int x, int y, const QImage &img) const
pick Get color from point.
Definition
colorpicker.cpp:19
ViewSolutions::ColorPicker::ColorPicker
ColorPicker()
Definition
colorpicker.cpp:15
colorpicker.h
ViewSolutions
The ViewSolutions namespace.
Definition
avatargenerator.cpp:14
ViewSolutions
src
colorpicker.cpp
Generated by
1.18.0