可以在python中更改PixelAccess的大小吗?
我在没有使用PIL的crop()函数的情况下裁剪了一个像素(只是为了好玩),但我找不到减小PixelAccess大小的方法 我可以更改所需部分的颜色,但我不能仅获得所需部分 谁能指导我如何从图像中获取所需的部分可以在python中更改PixelAccess的大小吗?,python,image,crop,Python,Image,Crop,我在没有使用PIL的crop()函数的情况下裁剪了一个像素(只是为了好玩),但我找不到减小PixelAccess大小的方法 我可以更改所需部分的颜色,但我不能仅获得所需部分 谁能指导我如何从图像中获取所需的部分 from PIL import Image i = Image.open('astro.bmp') pixels = i.load() width, height = i.size all_pixels = [] print(type(pixels)) #image resolut
from PIL import Image
i = Image.open('astro.bmp')
pixels = i.load()
width, height = i.size
all_pixels = []
print(type(pixels))
#image resolution is 1024 x 768
for x in range(width) :
for y in range(height) :
ap = pixels[x, y]
all_pixels.append(ap)
center_x = 40
center_y = 40
crop_width = 180
crop_height = 180
#for cropping
for x in range(crop_width) :
center_y = 40
for y in range(crop_height) :
pixels[center_x, center_y] = all_pixels[768 * center_x + center_y]
center_y += 1
center_x += 1
center_x = 40
# to change color of the required region
for x in range(crop_width) :
center_y = 40
for y in range(crop_height) :
pixels[center_x, center_y] = 253
center_y += 1
center_x += 1
i.save('out.bmp')
添加一些您试图让他人帮助您的代码:)PS-欢迎使用SO!谢谢@garfbradaz,我已经添加了全部代码。