现在的位置: 首页 > 综合 > 正文

[Java] 从图片URL中读取字节数组

2013年03月24日 ⁄ 综合 ⁄ 共 385字 ⁄ 字号 评论关闭

ByteArrayOutputStream baos = null;

  try

  {

   URL u = new URL(strUrl);

   BufferedImage image = ImageIO.read(u);

   

         //convert BufferedImage to byte array

   baos = new ByteArrayOutputStream();

   ImageIO.write( image, "jpg", baos);

   baos.flush();

   

   return baos.toByteArray();

  }

  catch (Exception e)

  {

  }

  finally

  {

   if(baos != null)

   {

    try {

     baos.close();

    } catch (IOException e) {

    }

   }

  }

抱歉!评论已关闭.