版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/The_MADAO/article/details/52601726
The Python Challenge Level-11 Solution
先附上我在Github上存放的代码仓库: The Python Challenge
这个题目感觉就很玄乎了,就只给我们一张图片,网页源码里空空如也
这里实际上是把一张图片拆分成两张来看。
我尝试了不同的奇偶拆分方式,最终还是选定了X轴和Y轴相加的方式来判断奇偶
from io import BytesIO
from PIL import Image
__author__ = 'Yuuki_Dach'
img = Image.open('cave.jpg')
width, height = img.size
even = Image.new('RGB', (width >> 1, height >> 1))
odd = Image.new('RGB', (width >> 1, height >> 1))
for i in range(width):
for j in range(height):
imgPixel = img.getpixel((i, j))
if (i + j) & 1 == 1:
odd.putpixel((i >> 1, j >> 1), imgPixel)
else:
even.putpixel((i >> 1, j >> 1), imgPixel)
even.show()
odd.show()