久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='R5JhS'></tfoot>

    <small id='R5JhS'></small><noframes id='R5JhS'>

    <legend id='R5JhS'><style id='R5JhS'><dir id='R5JhS'><q id='R5JhS'></q></dir></style></legend>
  1. <i id='R5JhS'><tr id='R5JhS'><dt id='R5JhS'><q id='R5JhS'><span id='R5JhS'><b id='R5JhS'><form id='R5JhS'><ins id='R5JhS'></ins><ul id='R5JhS'></ul><sub id='R5JhS'></sub></form><legend id='R5JhS'></legend><bdo id='R5JhS'><pre id='R5JhS'><center id='R5JhS'></center></pre></bdo></b><th id='R5JhS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='R5JhS'><tfoot id='R5JhS'></tfoot><dl id='R5JhS'><fieldset id='R5JhS'></fieldset></dl></div>

      • <bdo id='R5JhS'></bdo><ul id='R5JhS'></ul>

      從內(nèi)存中發(fā)送圖像

      Send image from memory(從內(nèi)存中發(fā)送圖像)

      <tfoot id='6hCuO'></tfoot>
      <i id='6hCuO'><tr id='6hCuO'><dt id='6hCuO'><q id='6hCuO'><span id='6hCuO'><b id='6hCuO'><form id='6hCuO'><ins id='6hCuO'></ins><ul id='6hCuO'></ul><sub id='6hCuO'></sub></form><legend id='6hCuO'></legend><bdo id='6hCuO'><pre id='6hCuO'><center id='6hCuO'></center></pre></bdo></b><th id='6hCuO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6hCuO'><tfoot id='6hCuO'></tfoot><dl id='6hCuO'><fieldset id='6hCuO'></fieldset></dl></div>

        <small id='6hCuO'></small><noframes id='6hCuO'>

      • <legend id='6hCuO'><style id='6hCuO'><dir id='6hCuO'><q id='6hCuO'></q></dir></style></legend>

          <bdo id='6hCuO'></bdo><ul id='6hCuO'></ul>

                  <tbody id='6hCuO'></tbody>
                本文介紹了從內(nèi)存中發(fā)送圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在嘗試為 Discord 機(jī)器人實現(xiàn)一個系統(tǒng),該系統(tǒng)可以動態(tài)修改圖像并將它們發(fā)送給機(jī)器人用戶.為此,我決定使用 Pillow (PIL) 庫,因為它對我的目的來說看起來簡單明了.

                I am trying to implement a system for a Discord bot that dynamically modifies images and sends them to the bot users. To do that, I decided to use the Pillow (PIL) library, since it seemed simple and straightforward for my purposes.

                這是我的工作代碼示例.它加載一個示例圖像,作為測試修改,在其上繪制兩條對角線,并將圖像作為 Discord 消息輸出:

                Here is an example of my working code. It loads an example image, as a test modification, draws two diagonal lines on it, and outputs the image as a Discord message:

                # Open source image
                img = Image.open('example_image.png')
                
                # Modify image
                draw = ImageDraw.Draw(img)
                draw.line((0, 0) + img.size, fill=128)
                draw.line((0, img.size[1], img.size[0], 0), fill=128)
                
                # Save to disk and create discord file object
                img.save('tmp.png', format='PNG')
                file = discord.File(open('tmp.png', 'rb'))
                
                # Send picture as message
                await message.channel.send("Test", file=file)
                

                這會導(dǎo)致我的機(jī)器人發(fā)出以下消息:

                This results in the following message from my bot:

                這行得通;但是,我想省略將圖像保存到硬盤驅(qū)動器并再次加載它的步驟,因為這似乎相當(dāng)?shù)托也槐匾?經(jīng)過一番谷歌搜索后,我遇到了以下解決方案;但是,它似乎不起作用:

                This works; however, I would like to omit the step of saving the image to the hard drive and loading it again, since that seems rather inefficient and unnecessary. After some googling I came across following solution; however, it doesn't seem to work:

                # Save to disk and create discord file object
                # img.save('tmp.png', format='PNG')
                # file = discord.File(open('tmp.png', 'rb'))
                
                # Save to memory and create discord file object
                arr = io.BytesIO()
                img.save(arr, format='PNG')
                file = discord.File(open(arr.getvalue(), 'rb'))
                

                這會導(dǎo)致以下錯誤消息:

                This results in the following error message:

                Traceback (most recent call last):
                    File "C:Users<username>AppDataLocalProgramsPythonPython38-32libsite-packagesdiscordclient.py", line 270, in _run_event
                        await coro(*args, **kwargs)
                    File "example_bot.py", line 48, in on_message
                        file = discord.File(open(arr.getvalue(), 'rb'))
                UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
                

                推薦答案

                discord.File 支持傳遞 io.BufferedIOBase 作為 fp 參數(shù).
                io.BytesIO 繼承自 <代碼>io.BufferedIOBase.
                這意味著您可以直接將 io.BytesIO 的實例作為 fp 來初始化 discord.File,例如:

                discord.File supports passing io.BufferedIOBase as the fp parameter.
                io.BytesIO inherits from io.BufferedIOBase.
                This means that you can directly pass the instance of io.BytesIO as fp to initialize discord.File, e.g.:

                arr = io.BytesIO()
                img.save(arr, format='PNG')
                arr.seek(0)
                file = discord.File(arr)
                

                另一個例子可以在 如何上傳圖片?discord.py 文檔中的常見問題解答部分.

                這篇關(guān)于從內(nèi)存中發(fā)送圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機(jī)器人?)
                Discord bot isn#39;t responding to commands(Discord 機(jī)器人沒有響應(yīng)命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關(guān)于我嗎?Discord 機(jī)器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機(jī)器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <tbody id='bW1TS'></tbody>
                  <i id='bW1TS'><tr id='bW1TS'><dt id='bW1TS'><q id='bW1TS'><span id='bW1TS'><b id='bW1TS'><form id='bW1TS'><ins id='bW1TS'></ins><ul id='bW1TS'></ul><sub id='bW1TS'></sub></form><legend id='bW1TS'></legend><bdo id='bW1TS'><pre id='bW1TS'><center id='bW1TS'></center></pre></bdo></b><th id='bW1TS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bW1TS'><tfoot id='bW1TS'></tfoot><dl id='bW1TS'><fieldset id='bW1TS'></fieldset></dl></div>

                        <bdo id='bW1TS'></bdo><ul id='bW1TS'></ul>
                      • <tfoot id='bW1TS'></tfoot>
                        1. <legend id='bW1TS'><style id='bW1TS'><dir id='bW1TS'><q id='bW1TS'></q></dir></style></legend>
                        2. <small id='bW1TS'></small><noframes id='bW1TS'>

                          主站蜘蛛池模板: 99精品欧美一区二区三区综合在线 | 99re6在线视频 | 久久久蜜桃 | 色播99| 国产激情一区二区三区 | 亚洲最大成人综合 | 色婷婷亚洲一区二区三区 | 久久久久国产精品 | 视频一区二区国产 | 成人午夜免费福利视频 | 欧美中文字幕一区 | 成人性视频在线播放 | 日韩欧美1区2区 | 日韩中文字幕 | 一区二区在线不卡 | 精品一区二区久久久久久久网站 | 正在播放一区二区 | 性做久久久久久免费观看欧美 | 国产成人精品a视频一区www | 成人一区av偷拍 | 日韩高清一区二区 | 在线观看av网站 | www.日韩 | 91久久综合| 欧美videosex性极品hd | 草久视频 | 91精品国产乱码久久久久久久久 | 欧美一区二区三区在线观看视频 | 欧美精品99 | 欧美在线观看黄色 | 国产精品一区视频 | 久在线观看 | 三级黄色片在线观看 | 国产黄色小视频在线观看 | 久久精品国产99国产精品 | 伊人网站视频 | 91免费版在线观看 | 国产日本精品视频 | av色站| 在线小视频 | 91精品国产麻豆 |