擅长:python、mysql、java
<p>保持像素数据的类型不变,并用“in”缩短if语句</p>
<pre><code>import Image
filename ="name.jpg"
picture = Image.open(filename, 'r')
_colors = [(0, 128, 0), (128, 128, 0), (128, 128, 128), (192, 128, 0), (128, 64, 0), (0, 192, 0), (128, 64, 128), (0, 0, 0)]
width, height = picture.size
for x in range(0, width):
for y in range(0, height):
current_color = picture.getpixel((x,y))
if current_color in _colors:
picture.putpixel((x,y), (0, 0, 0))
picture.show()
</code></pre>