Here you can find the source of Img2ByteByUrl(String strUrl)
public static byte[] Img2ByteByUrl(String strUrl)
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; import javax.imageio.ImageIO; public class Main { public static byte[] Img2ByteByUrl(String strUrl) { ByteArrayOutputStream baos = null; try {//from w w w. ja v a2 s .c o m 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) { } } } return null; } }