TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
<%@ 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) {
} %>
源码下载:http://file.javaxxz.com/2014/10/29/235646234.zip |
|