-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectpix.h
44 lines (39 loc) · 1.11 KB
/
rectpix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef PIX_H
#define PIX_H
#include <QPixmap>
#include <QImage>
#include <QBitmap>
#include <QPainter>
#include <QDebug>
class Pix
{
public:
QPixmap round(QImage im){
QPixmap img = rect(im);
QBitmap mask(img.size());
QPainter painter(&mask);
mask.fill(Qt::white);
painter.setBrush(Qt::black);
painter.drawEllipse(QPoint(mask.width()/2, mask.height()/2), img.width()/2, img.height()/2);
img.setMask(mask);
return img;
}
QPixmap rect(QImage im){
QImage copy;
if(im.height() > im.width()){
copy = im.copy( 0, (im.height()-im.width())/2, im.width(), im.width());
}
else{
copy = im.copy( (im.width()-im.height())/2, 0, im.height(), im.height());
}
QPixmap img = QPixmap::fromImage(copy);
QBitmap mask(img.size());
QPainter painter(&mask);
mask.fill(Qt::white);
painter.setBrush(Qt::black);
painter.drawEllipse(QPoint(mask.width()/2, mask.height()/2), img.width()/2, img.height()/2);
img.setMask(mask);
return img;
}
};
#endif