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

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) {
    }
   }
  }
posted @ 2012-12-04 16:32  java程序员-c  阅读(1266)  评论(0编辑  收藏  举报