-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcropImage.py
37 lines (31 loc) · 1.51 KB
/
cropImage.py
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
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QRubberBand, QLabel
from PyQt5.QtCore import QRect
class cropImage(QLabel):
def __init__(self, outputImageLabel, stateManager, parentQWidget=None):
super(cropImage, self).__init__(parentQWidget)
self.initUI(stateManager)
self.stateManager = stateManager
self.outputImageLabel = outputImageLabel
def initUI(self, stateManager):
if stateManager.outputSource != '':
inputImage = QtGui.QPixmap(stateManager.outputSource)
else:
inputImage = QtGui.QPixmap(stateManager.inputSource)
self.setWindowTitle("Crop Image")
self.setPixmap(inputImage)
def mousePressEvent(self, eventQMouseEvent):
self.originQPoint = eventQMouseEvent.pos()
self.currentQRubberBand = QRubberBand(QRubberBand.Rectangle, self)
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, QtCore.QSize()))
self.currentQRubberBand.show()
def mouseMoveEvent(self, eventQMouseEvent):
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, eventQMouseEvent.pos()).normalized())
def mouseReleaseEvent(self, eventQMouseEvent):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRubberBand.deleteLater()
cropQPixmap = self.pixmap().copy(currentQRect)
self.outputImageLabel.setPixmap(QtGui.QPixmap(cropQPixmap))
self.stateManager.imageOperation(
cropQPixmap.toImage())