MiraiForum

    • 注册
    • 登录
    • 搜索
    • 热门
    • 最新
    • 未解决
    • 标签
    • 群组
    • 友情链接

    求助! 发送图片失败

    开发交流
    3
    11
    556
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • D
      Danile0 最后由 编辑

      报错:

      java.lang.IllegalArgumentException: Unsupported image type (mirai) for ExternalResource net.mamoe.mirai.internal.utils.ExternalResourceImplByFile@e44b38d, considering use gif/png/bmp/jpg format. image header:
              at net.mamoe.mirai.internal.message.image.ImageDecoderKt.calculateImageInfo(ImageDecoder.kt:159)
              at net.mamoe.mirai.internal.contact.CommonGroupImpl$uploadImage$lambda-16$$inlined$runBIO$1.invoke(CoroutineUtils.kt:23)
              at kotlinx.coroutines.InterruptibleKt.runInterruptibleInExpectedContext(Interruptible.kt:51)
              at kotlinx.coroutines.InterruptibleKt.access$runInterruptibleInExpectedContext(Interruptible.kt:1)
              at kotlinx.coroutines.InterruptibleKt$runInterruptible$2.invokeSuspend(Interruptible.kt:43)
              at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
              at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
              at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
              at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
              at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
              at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
              at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
              at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
      

      代码:

      byte[] bytes = Base64.getDecoder().decode(stringR.getData());
                          String path = dataFile.getPath().substring(0, dataFile.getPath().length() - 9);
                          File file = FileUtils.byte2image(bytes, path , UUID.randomUUID() + ".png");
      
                          ExternalResource resource = ExternalResource.create(file);
                          Image image = event.getGroup().uploadImage(resource);
                          MessageChain messageChain = new MessageChainBuilder()
                                  .append(new At(event.getSender().getId()))
                                  .append("\n")
                                  .append(image)
                                  .build();
                          event.getGroup().sendMessage(messageChain);
      
      1 条回复 最后回复 回复 引用 0
      • 起舞弄清影
        起舞弄清影 摸鱼 最后由 编辑

        你这明显是上传了不支持的格式
        试试用ImageIO转成png格式

        D 1 条回复 最后回复 回复 引用 0
        • D
          Danile0 @起舞弄清影 最后由 编辑

          @起舞弄清影 在 求助! 发送图片失败 中说:

          你这明显是上传了不支持的格式
          试试用ImageIO

          我把文件命名为.png了呀

          1 条回复 最后回复 回复 引用 0
          • 起舞弄清影
            起舞弄清影 摸鱼 最后由 编辑

            不是,改后缀名是不能改变图片格式的,你得用库转成png才行

            1 条回复 最后回复 回复 引用 0
            • 起舞弄清影
              起舞弄清影 摸鱼 最后由 编辑

              不是说你把名字改成.png就可以变成png格式的,它里面的图片编码是不会因为改了名字就改变的

              1 条回复 最后回复 回复 引用 0
              • 起舞弄清影
                起舞弄清影 摸鱼 最后由 编辑

                计算机还没有智能到这个程度

                1 条回复 最后回复 回复 引用 0
                • 起舞弄清影
                  起舞弄清影 摸鱼 最后由 编辑

                  我寻思着你都会写Java了,怎么还会干出这事来

                  D 1 条回复 最后回复 回复 引用 0
                  • D
                    Danile0 @起舞弄清影 最后由 编辑

                    @起舞弄清影
                    =。= ,这样就行了吧

                    try {
                                            byte[] bytes = Base64.getDecoder().decode(stringR.getData());
                                            String path = dataFile.getPath().substring(0, dataFile.getPath().length() - 9);
                                            File file = new File(path + "serverInfo.png");
                                            ImageIO.write(ImageIO.read(new ByteArrayInputStream(bytes)), "png", new File(file.getPath()));
                                            ExternalResource resource = ExternalResource.create(file);
                                            Image image = event.getGroup().uploadImage(resource);
                                            MessageChain messageChain = new MessageChainBuilder()
                                                    .append(new At(event.getSender().getId()))
                                                    .append("\n")
                                                    .append(image)
                                                    .build();
                                            event.getGroup().sendMessage(messageChain);
                                        }catch (Exception e){
                                            e.printStackTrace();
                                            MessageUtil.sendGroupMessage(event, "获取图片失败!");
                                        }
                    
                    D 起舞弄清影 2 条回复 最后回复 回复 引用 0
                    • D
                      Danile0 @Danile0 最后由 编辑

                      @Danile0 第5行多了个new FIle(); 忽略就行

                      1 条回复 最后回复 回复 引用 0
                      • cssxsh
                        cssxsh 最后由 编辑

                        considering use gif/png/bmp/jpg format. image header:

                        如果这个就是完整的日志, header: 后面没有其他东西
                        那么说明你传了一个空文件

                        1 条回复 最后回复 回复 引用 0
                        • 起舞弄清影
                          起舞弄清影 摸鱼 @Danile0 最后由 编辑

                          @Danile0 对

                          1 条回复 最后回复 回复 引用 0
                          • 1 / 1
                          • First post
                            Last post
                          Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact