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

yipeiwu_com6年前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 serial 获取所有的串口名称的实例

如下所示: #!/usr/bin/env python # -*- coding: utf-8 -* import serial import serial.tools.list...

python 模拟银行转账功能过程详解

python 模拟银行转账功能过程详解

首先画出流程图,流程图与现实代码有出入,因为刚开始画流程图的时候,有些东西没考虑进去,后来写着写着就慢慢能想起来并实现了。 另有一点经验推荐给新手朋友,如果说碰到一个项目无从下手的话,...

Python实现随机漫步功能

Python实现随机漫步功能

随机漫步生成是无规则的,是系统自行选择的结果。根据设定的规则自定生成,上下左右的方位,每次所经过的方向路径。 首先,创建一个RandomWalk()类和fill_walk()函数 ran...

WIn10+Anaconda环境下安装PyTorch(避坑指南)

WIn10+Anaconda环境下安装PyTorch(避坑指南)

这些天安装 PyTorch,遇到了一些坑,特此总结一下,以免忘记。分享给大家。 首先,安装环境是:操作系统 Win10,已经预先暗转了 Anaconda。 1. 为 PyTorch 创建...

实例讲解python函数式编程

函数式编程是使用一系列函数去解决问题,按照一般编程思维,面对问题时我们的思考方式是“怎么干”,而函数函数式编程的思考方式是我要“干什么”。 至于函数式编程的特点暂不总结,我们直接拿例子来...