【问题标题】:how to work with aiogram photo without downloading it to disk如何在不将其下载到磁盘的情况下使用 aiogram 照片
【发布时间】:2023-02-08 02:18:45
【问题描述】:

我想获取二维码的照片并解密,但我不想将二维码保存到磁盘, await message.photo[-1].download(destination_file = "aaa.png")

我可以在不保存的情况下以某种方式处理生成的图像吗?

import cv2
from pyzbar import pyzbar
@dp.message_handler(state=QrScanState.Qr_Scan_Data, content_types=types.ContentType.PHOTO)
async def send_qr_data(message: types.Message, state: FSMContext):
    await message.photo[-1].download(destination_file = "aaa.png")
    img = cv2.imread("aaa.png")
    barcodes = pyzbar.decode(img)
    await bot.send_message(chat_id = message.from_user.id, text = barcodes[0].data.decode())
    await state.finish()

我试图在不保存照片的情况下工作,但据我所知,照片的 file_id 在列表中

img = cv2.imread(message.photo[-1])

类型错误:无法将对象转换为“文件名”的“str”

【问题讨论】:

    标签: python aiogram


    【解决方案1】:

    遇到同样的错误,我认为问题是如何接收图片。如果您尝试直接设置 img = cv2.imread('test.png') 它应该可以工作。但我可能错了,如果是这样,请纠正我并告诉我哪里出了问题

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 2022-06-29
      • 2012-03-18
      • 1970-01-01
      • 2019-08-10
      相关资源
      最近更新 更多