记一次放内存切图|BytesIO|PIL库
from io import BytesIO
from PIL import Image
screenshot=open('./test.png','rb').read()
#放入内存
img_io = BytesIO()
img_io.write(screenshot)
img = Image.open(img_io)
#切出题目
question = img.crop((200,300,900,520))
#新建一个画布
new_img = Image.new('RGB',(700,220))
#贴入新画布
new_img.paste(question,(0,0,700,220))
#内存对象
new_img_fb = BytesIO()
new_img.save(new_img_fb,'png')
with open('./test2.png','wb') as f:
f.write(new_i
共有 0 条评论