解决思路:
先要根据URL获取到图片,然后在根据得到的图片进行操作。
需要的:
import java.net.URL;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import javax.imageio.ImageIO;
1:根据URL获取图片:
private BufferedImage getBufferedImage(String imgUrl) {
URL url = null;
InputStream is = null;
BufferedImage img = null;
try {
url = new URL(imgUrl);
is = url.openStream();
img = ImageIO.read(is);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return img;
}
2:将获取到的图片进行操作:
Map map = new HashMap();
BufferedImage image=getBufferedImage(imgUrl);
if (image!=null)
{
/*System.out.println("图片高度:"+image.getHeight());
System.out.println("图片宽度:"+image.getWidth()); */
map.put("Height", String.valueOf(image.getHeight()));
map.put("Width", String.valueOf(image.getWidth()));
}
else
{
System.out.println("图片不存在!");
}
return map;