用户:开朗的震雷霄查看:0 回复:1 评论:0 创建时间:2021-08-28T18:52:32
【作品展示】

【作品介绍】
运行就行了
【作品源代码】
import sys
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PIL import Image,ImageFilter,ImageQt
from ui_process_img import Ui_process_img
class ProcessImg(QMainWindow,Ui_process_img):
def __init__(self):
super().__init__()
self.setupUi(self)
# 图片文档路径
self.file = None
#滤镜
self.filters = {
"模糊滤镜": ImageFilter.BLUR,
"轮廓滤镜":ImageFilter.CONTOUR,
"边缘增强滤镜": ImageFilter.EDGE_ENHANCE,
"浮雕滤镜":ImageFilter.EMBOSS,
"锐化滤镜":ImageFilter.SHARPEN,
"平滑滤镜":ImageFilter.SMOOTH,
}
# 按钮信号
self.pbtn_file.clicked.connect(self.select_file)
self.pbtn_process.clicked.connect(self.process_img)
#标签内图片大小自适应
self.lb_input_img.setScaledContents(True)
self.lb_output_img.setScaledContents(True)
self.show()
def select_file(self):
file_path = QFileDialog.getOpenFileName(caption="选择文件",filter="(*.jpg *.png)")
if file_path[0]:
self.file = file_path[0]
img_pix = QPixmap(self.file)
self.lb_input_img.setPixmap(img_pix)
else:
print("请重新选择图片文件")
def process_img(self):
#打开图片
img = Image.open(self.file)
#获取列表选择控件的当前选择项内容
text = self.cb_filter_list.currentText()
#对图像尽享滤镜处理
img_temp = img.filter(self.filters[text]).convert("RGBA")
#将滤镜处理结果变成能被PySide2识别的图像数据
img_qt = ImageQt.ImageQt(img_temp)
#将图像数据转换成 QPixmap 类型
img_pix = QPixmap.fromImage(img_qt)
#设置标签内容为处理后的照片
self.lb_output_img.setPixmap(img_pix)
if __name__ =="__main__":
app = QApplication(sys.argv)
window = ProcessImg()
sys.exit(app.exec_())
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn