/**
* 獲取服務器上的圖片信息*
* @param iconUrl
* @return
* @date
*/
private BufferedImage getIconInfo(String iconUrl) {
BufferedImage sourceImg = null;
try {
InputStream murl = new URL("http://xxxxx/4744ecb7-a602-48e0-8a3d-6e7132ad8eaa.jpg").openStream();
sourceImg = ImageIO.read(murl);
System.out.println(sourceImg.getWidth()); // 源圖寬度
System.out.println(sourceImg.getHeight()); // 源圖高度
System.out.println(sourceImg.getWidth() * sourceImg.getHeight());
System.out.println(sourceImg.getData());
} catch (IOException e) {
logger.error("獲取圖片異常。", e);
}
return sourceImg;
}
/**
* 獲取服務器上的圖片信息
*
* @throws FileNotFoundException
* @throws IOException
*/
public BufferedImage getImg(String iconUrl) {
BufferedImage image = null;
try {
URL url = new URL("http://xxxxx/4744ecb7-a602-48e0-8a3d-6e7132ad8eaa.jpg");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
image = ImageIO.read(connection.getInputStream());
int srcWidth = image.getWidth(); // 源圖寬度
int srcHeight = image.getHeight(); // 源圖高度
System.out.println("srcWidth = " + srcWidth);
System.out.println("srcHeight = " + srcHeight);
} catch (Exception e) {
logger.error("獲取圖片異常。", e);
}
return image;
}
參考:http://blog.csdn.net/u010648555/article/details/51647557