gpt4 book ai didi

python - 如何平滑 pyqt4 上曲线和对角线上的锯齿状边缘?

转载 作者:行者123 更新时间:2023-12-01 02:55:35 24 4
gpt4 key购买 nike

我正在画一条线,但如何保持线条“锯齿”自由且干净?

enter image description here

这是绘制上面图像的代码。这里我们可能会注意到图像充满了锯齿状边缘。

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtGui, QtCore

class Example(QtGui.QWidget):

def __init__(self):
super(Example, self).__init__()
self.initUI()

def initUI(self):
self.drawingPanel = DrawingPanel(self)

verticalLayout = QtGui.QVBoxLayout( self )
verticalLayout.addWidget( self.drawingPanel )

self.setLayout( verticalLayout )
self.resize( 400, 300 )

self.setWindowTitle('Review')
self.show()


class DrawingPanel(QtGui.QGraphicsView):

def __init__( self, parent ):
super( DrawingPanel, self ).__init__( parent )

scene = QtGui.QGraphicsScene()
self.setScene( scene )

pencil = QtGui.QPen( QtCore.Qt.black, 2, QtCore.Qt.SolidLine )
self.scene().addLine( QtCore.QLineF(0, 0, 300, 600), pencil )


def main():

app = QtGui.QApplication( sys.argv )
ex = Example()
sys.exit( app.exec_() )


if __name__ == '__main__':
main()

这里是图像的缩放:

enter image description here

有关它的其他一些问题:

  1. Smoothing jagged edges without anti-aliasing - Unity3D
  2. How to enable anti-aliasing in A-Frame?

最佳答案

您必须在 QGraphicsView 中启用抗锯齿功能:

class DrawingPanel(QtGui.QGraphicsView):

def __init__(self, parent):
QtGui.QGraphicsView.__init__(self, parent)
self.setRenderHint(QtGui.QPainter.Antialiasing)
[...]

关于python - 如何平滑 pyqt4 上曲线和对角线上的锯齿状边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44233028/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com