猫史档案馆


【Python作品分享】滤镜处理小程序【作业帖】

用户:一邪眸白虎一一邪眸白虎一查看:0 回复:0 评论:0 创建时间:2020-09-26T11:10:21


【作品展示】

center_image

 

【作品介绍】

图片滤镜处理

 

【作品源代码】

import sys
from PIL import Image,ImageFilter,ImageQt
from PySide2.QtWidgets import *
from PySide2.QtGui import *
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_pbtn = QFileDialog.getOpenFileName(caption='选择图片文件',filter="(*.jpg)")
        if file_pbtn[0]:
            self.file = file_pbtn[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")
        img_qt = ImageQt.ImageQt(img_temp)
        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


回复

上一页1 页 / 共 0下一页