如何抓取canvas画布中的图片

如何抓取canvas画布中的图片

网络页面中存放图片的形式有很多
这里说一下canvas格式时怎么获取

String fullImgJs = "return document.getElementsByClassName(\"元素className\")[0].children[0].toDataURL(\"image/png\");";
String imgFilePath = "c://img.png";
String imgInfo = ((JavascriptExecutor) driver).executeScript(fullImgJs).toString();
if (imgInfo != null && imgInfo.contains("data")) {
	imgInfo = imgInfo.substring(imgInfo.indexOf(",") + 1);
	byte[] data = new BASE64Decoder().decodeBuffer(imgInfo);
	FileUtils.writeByteArrayToFile(new File(imgFilePath), data);
}

在这里插入图片描述
作者:香芋味的猫丶

要在Tkinter的Canvas画布上实现图片翻页,你可以使用PIL库(Python Imaging Library)来加载和处理图像,并通过Canvas对象的`create_image`方法将图像显示在画布上。以下是一个示例代码: ```python import tkinter as tk from PIL import ImageTk, Image root = tk.Tk() canvas = tk.Canvas(root, width=400, height=400) canvas.pack() # 图片列表 image_list = ["image1.jpg", "image2.jpg", "image3.jpg"] current_image = 0 def show_next_image(): global current_image current_image = (current_image + 1) % len(image_list) show_image() def show_previous_image(): global current_image current_image = (current_image - 1) % len(image_list) show_image() def show_image(): canvas.delete("image") image = Image.open(image_list[current_image]) image = image.resize((400, 400), Image.ANTIALIAS) photo = ImageTk.PhotoImage(image) canvas.create_image(0, 0, image=photo, anchor=tk.NW, tags="image") canvas.image = photo next_button = tk.Button(root, text="下一张", command=show_next_image) next_button.pack() previous_button = tk.Button(root, text="上一张", command=show_previous_image) previous_button.pack() show_image() root.mainloop() ``` 在这个示例,我们创建了一个Canvas对象并设置其大小。我们定义了一个图片列表和一个当前图片的索引变量`current_image`。然后,我们定义了两个按钮,分别用于显示下一张和上一张图片。 `show_next_image`和`show_previous_image`函数用于切换到下一张和上一张图片,并调用`show_image`函数来在画布上显示图片。`show_image`函数首先删除之前的图片(通过`canvas.delete("image")`),然后加载当前图片并调整大小,最后通过`canvas.create_image`方法将图片显示在画布上。 通过点击按钮,你可以在画布上翻页显示不同的图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

香芋味的猫

你的鼓励的我继续创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值