首页 新闻 会员 周边

python 将canvas 转换为图片

0
悬赏园豆:5 [已关闭问题] 关闭于 2020-01-17 22:08

想把这个弄成图片保存,但是发现是canvas ,请问python怎么把这个直接变成图片或者base64 也行...

永远跟党走i的主页 永远跟党走i | 小虾三级 | 园豆:1519
提问于:2020-01-17 21:26
< >
分享
所有回答(1)
0

img = driver.find_element_by_xpath("//canvas[@class='canvas']")
location = img.location
size = img.size

top, buttom, left, right = location["y"], location["y"] + size["height"], location["x"], location["x"] + size["width"]
screen_shot = driver.get_screenshot_as_png()
screen_shot = Image.open(BytesIO(screen_shot))
captcha = screen_shot.crop((int(left), int(top), int(right), int(buttom)))
captcha.save("captcha.png")
faBBB | 园豆:202 (菜鸟二级) | 2020-12-29 18:32

后面是这样弄的

支持(0) 反对(0) 永远跟党走i | 园豆:1519 (小虾三级) | 2020-12-29 21:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册