Answer the question
In order to leave comments, you need to log in
Why does a QImage get ragged after scaled()?
On the main form, a QGraphicsView called paint_area of size 400x400.
An object of the PaintScene(QGraphicsScene) class of the form
class PaintScene(QGraphicsScene):
prev = None
color = Qt.black
width = 10
strong = 10
def __init__(self):
super().__init__()
pass
def mousePressEvent(self, event):
self.addEllipse(
event.scenePos().x() - self.width / 2,
event.scenePos().y() - self.width / 2,
self.width,
self.width,
QPen(Qt.NoPen),
QBrush(self.color))
self.prev = event.scenePos()
def mouseReleaseEvent(self, event):
self.prev = None
def mouseMoveEvent(self, event):
if self.prev:
self.addLine(
self.prev.x(),
self.prev.y(),
event.scenePos().x(),
event.scenePos().y(),
QPen(self.color, self.width, Qt.SolidLine, Qt.RoundCap))
self.prev = event.scenePos()
def clear_area(self):
self.clear()
def get_image(self):
view = self.paint_area
sceneRect = view.sceneRect().toRect() #(0, 0, 400, 400)
sceneRect.adjust(1, 1, -1, -1) #(1, 1, 398, 398) удаляем рамку
pixMap = view.grab(sceneRect)
image = pixMap.toImage()
image = image.scaled(30, 30)
return image
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question