PyQt/Test/C++中修改PyQt对象/Test.py

71 lines
2 KiB
Python
Raw Normal View History

2020-03-02 21:05:24 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2021-07-13 14:52:26 +08:00
"""
2020-03-02 21:05:24 +08:00
Created on 2020年3月2日
@author: Irony
2021-07-13 14:52:26 +08:00
@site: https://pyqt.site , https://github.com/PyQt5
2020-03-02 21:05:24 +08:00
@email: 892768447@qq.com
@file:
@description: 冷色调
2021-07-13 14:52:26 +08:00
"""
2020-03-02 21:05:24 +08:00
import sys
from ctypes import CDLL
from time import time
try:
2021-07-13 14:52:26 +08:00
# For PyQt5
try:
from PyQt5 import sip
except ImportError:
import sip
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout
except ImportError:
# For PySide2
import shiboken2
from PySide2.QtCore import Qt
from PySide2.QtGui import QImage, QPixmap
from PySide2.QtWidgets import QApplication, QWidget, QLabel, QSlider, QVBoxLayout
2020-03-02 21:05:24 +08:00
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QVBoxLayout(self)
self.imgLabel = QLabel(self)
self.coldSlider = QSlider(Qt.Horizontal, self)
self.coldSlider.valueChanged.connect(self.doChange)
self.coldSlider.setRange(0, 255)
layout.addWidget(self.imgLabel)
layout.addWidget(self.coldSlider)
# 加载图片
self.srcImg = QImage('src.jpg')
self.imgLabel.setPixmap(QPixmap.fromImage(self.srcImg).scaledToWidth(800, Qt.SmoothTransformation))
# DLL库
self.dll = CDLL('Cold.dll')
print(self.dll)
def doChange(self, value):
t = time()
img = self.srcImg.copy() # 复制一份
2021-07-13 14:52:26 +08:00
if 'sip' in sys.modules:
# For PyQt5
self.dll.cold(sip.unwrapinstance(img), value)
elif 'shiboken2' in sys.modules:
# For PySide2
self.dll.cold(shiboken2.getCppPointer(img)[0], value)
2020-03-02 21:05:24 +08:00
self.imgLabel.setPixmap(QPixmap.fromImage(img).scaledToWidth(800, Qt.SmoothTransformation))
print('use time:', time() - t)
if __name__ == "__main__":
app = QApplication(sys.argv)
view = Window()
view.show()
sys.exit(app.exec_())