python实现图片变亮或者变暗的方法

yipeiwu_com5年前Python基础

本文实例讲述了python实现图片变亮或者变暗的方法。分享给大家供大家参考。具体实现方法如下:

import Image
# open an image file (.jpg or.png) you have in the working folder
im1 = Image.open("angelababy.jpg")
# multiply each pixel by 0.9 (makes the image darker)
# works best with .jpg and .png files, darker < 1.0 < lighter
# (.bmp and .gif files give goofy results)
# note that lambda is akin to a one-line function
im2 = im1.point(lambda p: p * 0.5)
# brings up the modified image in a viewer, simply saves the image as
# a bitmap to a temporary file and calls viewer associated with .bmp
# make certain you have associated an image viewer with this file type
im2.show()
# save modified image to working folder as Audi2.jpg
im2.save("angelababy2.jpg")

运行效果如下所示:

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python编程把二叉树打印成多行代码

题目描述 从上到下按层打印二叉树,同一层结点从左至右输出。每一层输出一行。 思路: 1、把每层节点的val值用list存好 2、把每层节点存好: ①计算当层节点的个数,这样就保证下一步每...

python文件操作之批量修改文件后缀名的方法

1、引言 需要把.dat 格式 转化成 .txt格式 2、实现 ##python批量更换后缀名 import os # 列出当前目录下所有的文件 files = os.listdir...

Python requests库用法实例详解

本文实例讲述了Python requests库用法。分享给大家供大家参考,具体如下: requests是Python中一个第三方库,基于 urllib,采用 Apache2 Licens...

Python 专题四 文件基础知识

前面讲述了函数、语句和字符串的基础知识,该篇文章主要讲述文件的基础知识(与其他语言非常类似). 一. 文件的基本操作 文件是指存储在外部介质(如磁盘)上数据的集合.文件的操作流程为: 打...

python射线法判断一个点在图形区域内外

用python 实现的代码:判断一个点在图形区域内外,供大家参考,具体内容如下 # -*-encoding:utf-8 -*- # file:class.py # """ 信息...