久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='ng7m1'><style id='ng7m1'><dir id='ng7m1'><q id='ng7m1'></q></dir></style></legend>

    <i id='ng7m1'><tr id='ng7m1'><dt id='ng7m1'><q id='ng7m1'><span id='ng7m1'><b id='ng7m1'><form id='ng7m1'><ins id='ng7m1'></ins><ul id='ng7m1'></ul><sub id='ng7m1'></sub></form><legend id='ng7m1'></legend><bdo id='ng7m1'><pre id='ng7m1'><center id='ng7m1'></center></pre></bdo></b><th id='ng7m1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ng7m1'><tfoot id='ng7m1'></tfoot><dl id='ng7m1'><fieldset id='ng7m1'></fieldset></dl></div>
      <bdo id='ng7m1'></bdo><ul id='ng7m1'></ul>
    1. <tfoot id='ng7m1'></tfoot>

      <small id='ng7m1'></small><noframes id='ng7m1'>

      1. 在畫布上擦筆

        Erasing pen on a canvas(在畫布上擦筆)
          <bdo id='IbkAm'></bdo><ul id='IbkAm'></ul>

          <small id='IbkAm'></small><noframes id='IbkAm'>

              <tbody id='IbkAm'></tbody>

          1. <tfoot id='IbkAm'></tfoot>

              <legend id='IbkAm'><style id='IbkAm'><dir id='IbkAm'><q id='IbkAm'></q></dir></style></legend>
              • <i id='IbkAm'><tr id='IbkAm'><dt id='IbkAm'><q id='IbkAm'><span id='IbkAm'><b id='IbkAm'><form id='IbkAm'><ins id='IbkAm'></ins><ul id='IbkAm'></ul><sub id='IbkAm'></sub></form><legend id='IbkAm'></legend><bdo id='IbkAm'><pre id='IbkAm'><center id='IbkAm'></center></pre></bdo></b><th id='IbkAm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IbkAm'><tfoot id='IbkAm'></tfoot><dl id='IbkAm'><fieldset id='IbkAm'></fieldset></dl></div>
                1. 本文介紹了在畫布上擦筆的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)功能正常的繪圖應(yīng)用程序,用于對(duì)圖像進(jìn)行一些分割.為此,我有兩層,原始圖像和我正在繪制的圖像層.

                  I have a functioning drawing application for some segmentation on images. For this I have two layers, the original image and the image layer I am drawing on.

                  我現(xiàn)在想實(shí)現(xiàn)一種擦除方法.我已經(jīng)實(shí)現(xiàn)了撤消功能,但我也希望用戶能夠選擇畫筆顏色"以便能夠擦除特定部分,例如油漆中的橡皮擦.我認(rèn)為這可以通過使用不透明的顏色進(jìn)行繪制來實(shí)現(xiàn),但這只會(huì)導(dǎo)致不繪制線條.

                  I now want to implement a method for erasing. I have implemented undo functionality, but I would also like the user to be able to select a brush "color" as to be able to erase specific parts, like the eraser in paint. I thought this would be possible by drawing with a color with opacity, but that just results in no line being drawn.

                  因此,我的目標(biāo)是畫一條線,去除圖像層中的像素值,以便我可以看到底層圖像

                  The goal for me is therefore to draw a line, that removes the pixel values in the image layer, such that I can see the underlying image

                  from PyQt5.QtWidgets import QApplication, QMainWindow, QMenuBar, QMenu, QAction
                  from PyQt5.QtGui import QIcon, QImage, QPainter, QPen
                  from PyQt5.QtCore import Qt, QPoint
                  from PyQt5.QtGui import QColor
                  import sys
                  
                  class Window(QMainWindow):
                      def __init__(self):
                          super().__init__()
                  
                          top = 400
                          left = 400
                          width = 800
                          height = 600
                  
                          self.setWindowTitle("MyPainter")
                          self.setGeometry(top, left, width, height)
                  
                          self.image = QImage(self.size(), QImage.Format_ARGB32)
                          self.image.fill(Qt.white)
                          self.imageDraw = QImage(self.size(), QImage.Format_ARGB32)
                          self.imageDraw.fill(Qt.transparent)
                  
                          self.drawing = False
                          self.brushSize = 2
                          self.brushColor = Qt.black
                          self.lastPoint = QPoint()
                  
                          self.change = False
                          mainMenu = self.menuBar()
                          changeColour = mainMenu.addMenu("changeColour")
                          changeColourAction = QAction("change",self)
                          changeColour.addAction(changeColourAction)
                          changeColourAction.triggered.connect(self.changeColour)
                  
                      def mousePressEvent(self, event):
                          if event.button() == Qt.LeftButton:
                              self.drawing = True
                              self.lastPoint = event.pos()
                  
                      def mouseMoveEvent(self, event):
                          if event.buttons() and Qt.LeftButton and self.drawing:
                              painter = QPainter(self.imageDraw)
                              painter.setPen(QPen(self.brushColor, self.brushSize,     Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
                              painter.drawLine(self.lastPoint, event.pos())
                              self.lastPoint = event.pos()
                              self.update()
                  
                      def mouseReleaseEvent(self, event):
                          if event.button == Qt.LeftButton:
                              self.drawing = False
                  
                      def paintEvent(self, event):
                          canvasPainter = QPainter(self)
                          canvasPainter.drawImage(self.rect(), self.image, self.image.rect())
                          canvasPainter.drawImage(self.rect(), self.imageDraw, self.imageDraw.rect())
                  
                      def changeColour(self):
                          if not self.change:
                              # erase
                              self.brushColor = QColor(255,255,255,0)
                          else:
                              self.brushColor = Qt.black
                          self.change = not self.change
                  
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      window = Window()
                      window.show()
                      app.exec()
                  

                  如何擦除像素子集?

                  在這個(gè)例子中,應(yīng)該為 changeColour 函數(shù)中的 self.brushColor 賦予什么顏色?

                  How to erase a subset of pixels?

                  As in this example what color should be given to self.brushColor in the changeColour function?

                  白色不是解決方案,因?yàn)閷?shí)際上底部的圖像是一個(gè)復(fù)雜的圖像,因此我想在擦除時(shí)再次使頂層透視".

                  The colour white is not the solution, because in reality the image at the bottom is a complex image, I therefore want to make the toplayer "see-through" again, when erasing.

                  推薦答案

                  你必須改變 compositionMode 到 QPainter::CompositionMode_Clear 并用 eraseRect().

                  You have to change the compositionMode to QPainter::CompositionMode_Clear and erase with eraseRect().

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Window(QtWidgets.QMainWindow):
                      def __init__(self):
                          super().__init__()
                          top, left, width, height = 400, 400, 800, 600
                          self.setWindowTitle("MyPainter")
                          self.setGeometry(top, left, width, height)
                  
                          self.image = QtGui.QImage(self.size(), QtGui.QImage.Format_ARGB32)
                          self.image.fill(QtCore.Qt.white)
                          self.imageDraw = QtGui.QImage(self.size(), QtGui.QImage.Format_ARGB32)
                          self.imageDraw.fill(QtCore.Qt.transparent)
                  
                          self.drawing = False
                          self.brushSize = 2
                          self._clear_size = 20
                          self.brushColor = QtGui.QColor(QtCore.Qt.black)
                          self.lastPoint = QtCore.QPoint()
                  
                          self.change = False
                          mainMenu = self.menuBar()
                          changeColour = mainMenu.addMenu("changeColour")
                          changeColourAction = QtWidgets.QAction("change", self)
                          changeColour.addAction(changeColourAction)
                          changeColourAction.triggered.connect(self.changeColour)
                  
                      def mousePressEvent(self, event):
                          if event.button() == QtCore.Qt.LeftButton:
                              self.drawing = True
                              self.lastPoint = event.pos()
                  
                      def mouseMoveEvent(self, event):
                          if event.buttons() and QtCore.Qt.LeftButton and self.drawing:
                              painter = QtGui.QPainter(self.imageDraw)
                              painter.setPen(QtGui.QPen(self.brushColor, self.brushSize, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
                              if self.change:
                                  r = QtCore.QRect(QtCore.QPoint(), self._clear_size*QtCore.QSize())
                                  r.moveCenter(event.pos())
                                  painter.save()
                                  painter.setCompositionMode(QtGui.QPainter.CompositionMode_Clear)
                                  painter.eraseRect(r)
                                  painter.restore()
                              else:
                                  painter.drawLine(self.lastPoint, event.pos())
                              painter.end()
                              self.lastPoint = event.pos()
                              self.update()
                  
                      def mouseReleaseEvent(self, event):
                          if event.button == QtCore.Qt.LeftButton:
                              self.drawing = False
                  
                      def paintEvent(self, event):
                          canvasPainter = QtGui.QPainter(self)
                          canvasPainter.drawImage(self.rect(), self.image, self.image.rect())
                          canvasPainter.drawImage(self.rect(), self.imageDraw, self.imageDraw.rect())
                  
                      def changeColour(self):
                          self.change = not self.change
                          if self.change:
                              pixmap = QtGui.QPixmap(QtCore.QSize(1, 1)*self._clear_size)
                              pixmap.fill(QtCore.Qt.transparent)
                              painter = QtGui.QPainter(pixmap)
                              painter.setPen(QtGui.QPen(QtCore.Qt.black, 2))
                              painter.drawRect(pixmap.rect())
                              painter.end()
                              cursor = QtGui.QCursor(pixmap)
                              QtWidgets.QApplication.setOverrideCursor(cursor)
                          else:
                              QtWidgets.QApplication.restoreOverrideCursor()
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      window = Window()
                      window.show()
                      sys.exit(app.exec())
                  

                  這篇關(guān)于在畫布上擦筆的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動(dòng)后進(jìn)度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動(dòng)時(shí),yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時(shí)顯示進(jìn)度條?)
                2. <tfoot id='2M1Pu'></tfoot>
                    <tbody id='2M1Pu'></tbody>
                  <i id='2M1Pu'><tr id='2M1Pu'><dt id='2M1Pu'><q id='2M1Pu'><span id='2M1Pu'><b id='2M1Pu'><form id='2M1Pu'><ins id='2M1Pu'></ins><ul id='2M1Pu'></ul><sub id='2M1Pu'></sub></form><legend id='2M1Pu'></legend><bdo id='2M1Pu'><pre id='2M1Pu'><center id='2M1Pu'></center></pre></bdo></b><th id='2M1Pu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2M1Pu'><tfoot id='2M1Pu'></tfoot><dl id='2M1Pu'><fieldset id='2M1Pu'></fieldset></dl></div>
                    • <small id='2M1Pu'></small><noframes id='2M1Pu'>

                        • <bdo id='2M1Pu'></bdo><ul id='2M1Pu'></ul>
                          <legend id='2M1Pu'><style id='2M1Pu'><dir id='2M1Pu'><q id='2M1Pu'></q></dir></style></legend>

                          1. 主站蜘蛛池模板: 国产精品免费看 | 欧美日韩免费一区二区三区 | 韩日一区二区 | 免费网站观看www在线观看 | 欧美视频精品 | 色综合88 | 狠狠se| 亚洲成人免费在线 | 欧美视频在线播放 | 国产精品久久久久久久免费看 | 一区二区三区在线观看视频 | 国内福利视频 | 黄色直接看 | 亚洲国产精品久久久久久久 | 香蕉视频一区二区 | 日韩中文字幕免费 | 黄色在线观看免费 | 在线免费观看黄色片 | 日韩精品在线视频 | 黄色片在线看 | 一区二区三区免费在线观看 | 日韩黄色小视频 | 国产福利视频在线观看 | 不卡的av | 日韩视频二区 | 成年人免费视频网站 | 亚洲视频免费观看 | 超碰在线中文字幕 | 少妇视频网站 | 在线中文字幕 | 一本久 | av在线一区二区三区 | 五月天黄色网址 | 欧美日韩国产一区二区 | 国产三级免费观看 | 亚洲综合一区二区三区 | 日韩精品视频免费在线观看 | 亚洲精品久久久 | 欧美日韩亚洲视频 | 能看的毛片| 久久久久亚洲 |