python如何将图片转换成黑白?
发布时间:2025-02-05 20:52:13
在python中,使用第三方库PIL将图片转换为黑白。方法是:1、使用PIL中Image对象的open方法读取需要转换的图片;2、使用Image对象的convert函数将图片转换为黑白。

本文的例子讲述了python通过pil将图片转换为黑白效果的方法。与您分享,供您参考。具体分析如下:
pil功能强大,convert方法可以轻松转换图片,下面的代码可以将图片转换为黑白效果
fromPILimportImage
image_file=Image.open("convert_image.png")#opencolourimage
image_file=image_file.convert('1')#convertimagetoblackandwhite
image_file.save('result.png')推荐课程:《Develop with Python on Windows》(微软官方-中文版)
下一篇 python如何写入多行字符串
