62,182
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Net;
public partial class zzzzz : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.gpssz.com/picture/2000147717/20070924155755.jpg");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
byte[] buffer = new byte[1024];
if (!response.ContentType.ToLower().StartsWith("text/"))
{
try
{
Stream outStream = new MemoryStream();
Stream inStream = response.GetResponseStream();
int bufferLength;
do
{
bufferLength = inStream.Read(buffer, 0, buffer.Length);
if (bufferLength > 0)
outStream.Write(buffer, 0, bufferLength);
}
while (bufferLength > 0);
outStream.Flush();
outStream.Seek(0, SeekOrigin.Begin);
inStream.Close();
Image image = Image.FromStream(outStream);
Response.Write(image.GetPropertyItem(0).Len);
outStream.Close();
Response.Write("image :=" + image.Width + "X" + image.Height);
image.Dispose();
}
catch (Exception ex)
{
Response.Write("非图像格式\r\n" + ex.Message);
}
}
else
{
Response.Write("非图像格式");
}
}
catch
{
Response.Write("找不到文件!");
}
}
}