asp.net 怎么样自动缩略分辨率上传过大的图片
2个回答
2013-09-16
展开全部
在网上找了一个程序,希望对你有帮助。
/// <summary>
/// 修改指定图片的分辨率
/// </summary>
/// <param name="fileFoldUrl">文件夹url</param>
/// <param name="fileName">文件名</param>
/// <param name="filePath">文件路径,带文件名</param>
/// <param name="_width">分辨率的宽</param>
/// <param name="_height">分辨率的高</param>
public void update_picture(string fileFoldUrl, string fileName, string filePath, int _width, int _height)
{
byte[] zp = this.load_pictMemory(filePath);
MemoryStream ms = new MemoryStream(zp);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
Bitmap btp = new Bitmap(img, _width, _height);
DirectoryInfo dti = new DirectoryInfo(fileFoldUrl);
FileInfo[] fis = dti.GetFiles();
string fileUrl = fileFoldUrl + fileName;
btp.Save(fileUrl);
}
/// <summary>
/// 获取指定文件流的字节大小
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns>byte[]</returns>
public byte[] load_pictMemory(string filePath)
{
byte[] pictData = null;
FileInfo fi = new FileInfo (filePath);
if (fi.Exists)
{
pictData = new byte[fi.Length];
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
br.Read(pictData, 0, Convert.ToInt32(fi.Length));
fs.Dispose();
}
else
{
HttpContext.Current.Response.Write("<script language='javascript'>alert('没有找到你所指定的图片')</script>");
}
return pictData;
}
/// <summary>
/// 修改指定图片的分辨率
/// </summary>
/// <param name="fileFoldUrl">文件夹url</param>
/// <param name="fileName">文件名</param>
/// <param name="filePath">文件路径,带文件名</param>
/// <param name="_width">分辨率的宽</param>
/// <param name="_height">分辨率的高</param>
public void update_picture(string fileFoldUrl, string fileName, string filePath, int _width, int _height)
{
byte[] zp = this.load_pictMemory(filePath);
MemoryStream ms = new MemoryStream(zp);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
Bitmap btp = new Bitmap(img, _width, _height);
DirectoryInfo dti = new DirectoryInfo(fileFoldUrl);
FileInfo[] fis = dti.GetFiles();
string fileUrl = fileFoldUrl + fileName;
btp.Save(fileUrl);
}
/// <summary>
/// 获取指定文件流的字节大小
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns>byte[]</returns>
public byte[] load_pictMemory(string filePath)
{
byte[] pictData = null;
FileInfo fi = new FileInfo (filePath);
if (fi.Exists)
{
pictData = new byte[fi.Length];
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
BinaryReader br = new BinaryReader(fs);
br.Read(pictData, 0, Convert.ToInt32(fi.Length));
fs.Dispose();
}
else
{
HttpContext.Current.Response.Write("<script language='javascript'>alert('没有找到你所指定的图片')</script>");
}
return pictData;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-16
展开全部
你定义的image控件只要指定的高度和宽度,图片就会自动缩放适应了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询