ImageMessage
图片消息,继承自 Message。
属性
| 属性 | 类型 | 说明 |
|---|---|---|
content | str | 图片描述文本 |
sender | str | 发送者 |
source | Source | 消息来源 |
type_label | str | 固定为 "图片消息" |
支持的操作
view、hover、scroll_to_visible、refresh、quote、copy、collect、forward、revoke、save_as、delete
特有方法
get_file_path()
获取图片的本地文件路径(通过右键复制获取剪贴板中的文件路径)。
- 返回
str— 图片文件绝对路径
read()
读取图片二进制数据。
- 返回
bytes— 图片文件内容
edit()
使用微信内置图片编辑器编辑图片。
示例
python
from pywxauto import Weixin, Event
wx = Weixin()
@wx.on(Event.IMAGE)
def on_image(weixin, chat, message):
# 获取图片文件路径
path = message.get_file_path()
print(f"图片路径: {path}")
# 读取图片数据
data = message.read()
with open("saved.png", "wb") as f:
f.write(data)
# 另存为
message.save_as("C:/images/received.png")