用户:努力学习的见习LYH查看:0 回复:0 评论:0 创建时间:2020-07-31T16:54:45
【作品展示】

【作品介绍】
一个可以将jpg,png图片进行加工处理的小程序,创作不易,请多支持!(本作品引用了我另外的一个作品,所以要将那一个作品下载好才能运行)
【作品源代码】
import sys
from PIL import Image, ImageFilter, ImageQt
from PySide2.QtWidgets import *
from PySide2.QtCore import QUrl
from PySide2.QtGui import *
from PySide2.QtWebEngineWidgets import QWebEngineView
from ui_filter import Ui_process_img
class ProcessImg(QMainWindow, Ui_process_img):
def __init__(self):
super().__init__()
self.setupUi(self)
# 图片文件路径
self.file = None
#self.init_set()
self.show()
#绑定信号与槽函数
self.pbtn_process.clicked.connect(self.filter_)
self.pbtn_file.clicked.connect(self.select_file)
self.pushbutton.cilcked.connect(self.save)
#标签内图片大小自适应
self.lb_input_img.setScaledContents(True)
self.lb_output_img.setScaledContents(True)
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.waring(self, "注意", "您选择的不是图片文件格式!")
def filter_(self):
index = self.cb_filter_list.currentText()
Indexs = {
'模糊滤镜': ImageFilter.BLUR, # 模糊
'轮廓滤镜': ImageFilter.CONTOUR, # 轮廓
'浮雕滤镜': ImageFilter.EMBOSS, #浮雕
'锐化滤镜': ImageFilter.SHARPEN, #锐化
'平滑滤镜': ImageFilter.SMOOTH, #平滑
'边缘增强滤镜': ImageFilter.EDGE_ENHANCE # 边缘增强
}
if self.file:
#打开图片
img = Image.open(self.file)
#对图片进行滤镜处理
img_temp = img.filter(Indexs[index]).convert("RGBA")
#将处理结果转换为能被 Pyside2 识别的图像数据
img_qt = ImageQt.ImageQt(img_temp)
#将图像数据转换成 QPixmap 类型
img_pix = QPixmap.fromImage(img_qt)
#设置标签内容为处理后的图片
self.lb_output_img.setPixmap(img_pix)
else:
QMessageBox.warning(self, "注意", "请先选择图片文件")
def save(self):
file_path = QFileDialog.getOpenFileName(
caption='保存图片', filter="(*.png)"
)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = ProcessImg()
sys.exit(app.exec_())
print(1)
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn