1、使用 new URL()

ImageIO.read(new URL(url));
 
获取图片有限制,可以读取图片的格式 :[BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, gif]
获取不到图片时返回为null,后续操作可能会报空指针
 
2、通过流的方式获取
 
public BufferedImage getUrlImage(String url) {
    byte[] bytes = HttpsUtils.getBytes(url);
    InputStream buffin = new ByteArrayInputStream(bytes,0,bytes.length);
    BufferedImage img = null;
    try {
        img = ImageIO.read(buffin);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return img;
}

相关文章:

  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
猜你喜欢
  • 2021-08-12
  • 2021-06-23
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案