首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

JSP远路获取图像的大小、宽度和高度

2012-12-18 
JSP远程获取图像的大小、宽度和高度%@ page contentTypetext/html charsetGBK %%@ page language

JSP远程获取图像的大小、宽度和高度
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" %>
<%@ page import= "java.net.* "%>
<%@ page import="java.awt.Image,java.awt.image.*" %>
<%@ page import="javax.imageio.*" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.io.*"%>

<%

//Image image = null;
try {
// Read from a file
// File file = new File("image.gif");
// image = ImageIO.read(file);
// Read from an input stream
// InputStream is = new BufferedInputStream(
// new FileInputStream("image.gif"));
// image = ImageIO.read(is);
// Read from a URL
URL url = new URL("http://www.java3z.com/cwbwebhome/images/logo.gif");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
long len = urlConnection.getContentLength();
if(len<=0){
out.print( "无法获知文件大小 ");
}else {
out.print( "文件大小为 " + len/1024+ "k "+"<br />");
}
BufferedImage bi = null;
bi = javax.imageio.ImageIO.read(url);
//image= javax.imageio.ImageIO.read(url);
int[] a = new int[2];
a[0]= bi.getWidth();
a[1] = bi.getHeight(); //获得 高度
int b=a[0];
out.print("图片宽:"+a[0]+"<br />");
out.print("图片高:"+a[1]);

} catch (IOException e) {
}

%>

热点排行