MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Unsolved [萌新求助] [JS] 如何将收到的图片保存到文件

    开发交流
    3
    3
    559
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      WXL-steven last edited by

      使用https://github.com/drinkal/Mirai-js进行开发

      如题,萌新不知如何将获取到的MiriaID转化为文件,如[mirai:image:{61A91159-072B-6677-CEED-BF813E0E76ED}.gif],是否有这方面的示例或者其他可供参考的源码,在此向各位大佬求助

      MrXiaoM 1 Reply Last reply Reply Quote 0
      • MrXiaoM
        MrXiaoM 童心未泯 @WXL-steven last edited by

        @wxl-steven js 我不熟悉,但是我记得
        net.mamoe.mirai.internal.message.OnlineImage 的实例是有个 image.getOriginUrl() 方法来获取图片的源地址的
        或许可以试试?

        在java中的暴力强制转化 (草

        	public static String getUrlFromImage(net.mamoe.mirai.message.data.Image image) {
        		return ((net.mamoe.mirai.internal.message.OnlineImage) image).getOriginUrl();
        	}
        
        1 Reply Last reply Reply Quote 0
        • Chuanwise
          Chuanwise last edited by

          public File saveImage(Image image) throws IOException {
                  URL url = new URL(Image.queryUrl(image));
                  final InputStream inputStream = url.openConnection().getInputStream();
          
                  final File imageFile = new File(image.getImageId());
                  if (!imageFile.isFile()) {
                      imageFile.createNewFile();
                  }
          
                  int packSize = 1024;
                  byte[] bytes = new byte[packSize];
                  int len = 0;
                  try (OutputStream outputStream = new FileOutputStream(imageFile)) {
                      while ((len = inputStream.read(bytes)) != -1) {
                          outputStream.write(bytes, 0, len);
                      }
                  }
                  inputStream.close();
          
                  return imageFile;
              }
          
          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact