pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="jprzmg3" id='R5JhS'><tfoot id='R5JhS'></tfoot><dl id='R5JhS'><fieldset id='R5JhS'></fieldset></dl></div>

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

      從內存中發送圖像

      Send image from memory(從內存中發送圖像)

      <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="jp7pk3r" 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>
                本文介紹了從內存中發送圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在嘗試為 Discord 機器人實現一個系統,該系統可以動態修改圖像并將它們發送給機器人用戶.為此,我決定使用 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)
                

                這會導致我的機器人發出以下消息:

                This results in the following message from my bot:

                這行得通;但是,我想省略將圖像保存到硬盤驅動器并再次加載它的步驟,因為這似乎相當低效且不必要.經過一番谷歌搜索后,我遇到了以下解決方案;但是,它似乎不起作用:

                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'))
                

                這會導致以下錯誤消息:

                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 參數.
                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 文檔中的常見問題解答部分.

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

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

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                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="dpghcwn" 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'>

                          主站蜘蛛池模板: 微学堂-电动能源汽车评测_电动车性能分享网 | 车件|铜件|车削件|车床加工|五金冲压件-PIN针,精密车件定制专业厂商【东莞品晔】 | 泥浆在线密度计厂家-防爆数字压力表-膜盒-远传压力表厂家-江苏大亚自控设备有限公司 | 净化车间装修_合肥厂房无尘室设计_合肥工厂洁净工程装修公司-安徽盛世和居装饰 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 密封圈_泛塞封_格莱圈-[东莞市国昊密封圈科技有限公司]专注密封圈定制生产厂家 | 三防漆–水性三防漆–水性浸渍漆–贝塔三防漆厂家 | 市政路灯_厂家-淄博信达电力科技有限公司 | 活性炭-蜂窝-椰壳-柱状-粉状活性炭-河南唐达净水材料有限公司 | 成都热收缩包装机_袖口式膜包机_高速塑封机价格_全自动封切机器_大型套膜机厂家 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 工业雾炮机_超细雾炮_远程抑尘射雾器-世纪润德环保设备 | 碳化硅,氮化硅,冰晶石,绢云母,氟化铝,白刚玉,棕刚玉,石墨,铝粉,铁粉,金属硅粉,金属铝粉,氧化铝粉,硅微粉,蓝晶石,红柱石,莫来石,粉煤灰,三聚磷酸钠,六偏磷酸钠,硫酸镁-皓泉新材料 | 挨踢网-大家的导航! | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 建筑工程资质合作-工程资质加盟分公司-建筑资质加盟 | 筒瓦厂家-仿古瓦-寺庙-古建琉璃瓦-宜兴市古典园林建筑陶瓷厂有限公司 | 破碎机_上海破碎机_破碎机设备_破碎机厂家-上海山卓重工机械有限公司 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 湖南印刷厂|长沙印刷公司|画册印刷|挂历印刷|台历印刷|杂志印刷-乐成印刷 | 协议书_协议合同格式模板范本大全 | 裹包机|裹膜机|缠膜机|绕膜机-上海晏陵智能设备有限公司 | 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 水轮机密封网 | 水轮机密封产品研发生产厂家 | 牛奶检测仪-乳成分分析仪-北京海谊| 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 立式_复合式_壁挂式智能化电伴热洗眼器-上海达傲洗眼器生产厂家 理化生实验室设备,吊装实验室设备,顶装实验室设备,实验室成套设备厂家,校园功能室设备,智慧书法教室方案 - 东莞市惠森教学设备有限公司 | 【灵硕展览集团】展台展会设计_展览会展台搭建_展览展示设计一站式服务公司 | 知企服务-企业综合服务(ZiKeys.com)-品优低价、种类齐全、过程管理透明、速度快捷高效、放心服务,知企专家! | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 车辆定位管理系统_汽车GPS系统_车载北斗系统 - 朗致物联 | 留学生辅导网-在线课程论文辅导-留学生挂科申诉机构 | 高压负荷开关-苏州雷尔沃电器有限公司 |