用户:G_W_L查看:0 回复:0 评论:0 创建时间:2020-08-19T11:28:20
【作品展示】

【作品介绍】
0
【作品源代码】
import sys
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PIL import Image,ImageFilter,ImageQt
from ui_process_image import Ui_process_img
from abc import to_sketch
from cba import to_char
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:
QMessageBox.warning(self, '注意', '请重新选择图片文件')
def process_img(self):
if self.file:
img=Image.open(self.file)
text=self.cb_filter_list.currentText()
if '滤镜' in text:
img_temp=img.filter(self.filters[text]).convert('RGBA')
elif text == '素描风格转化':
img_temp = to_sketch(img)
elif text == '字符串风格转化':
img_temp = to_char(img)
img_qt = ImageQt.ImageQt(img_temp)
img_pix=QPixmap.fromImage(img_qt)
self.lb_output_img.setPixmap(img_pix)
else:
QMessageBox.warning(self,'注意','请选择图片文件')
if __name__=='__main__':
app=QApplication(sys.argv)
window=ProcessImg()
sys.exit(app.exec_())
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn