代码求改正 ASP.NET上传图片并生成缩略图~~~大侠在哪里~
http://hi.baidu.com/%C8%A2%C1%CB%BB%A8%C4%BE%C0%BC/blog/item/aa9d2ef1eade768d58ee901e...
http://hi.baidu.com/%C8%A2%C1%CB%BB%A8%C4%BE%C0%BC/blog/item/aa9d2ef1eade768d58ee901e.html
代码带长. 有劳大家来我空间看下. 展开
代码带长. 有劳大家来我空间看下. 展开
展开全部
/// <summary>
/// 为图片生成缩略图
/// </summary>
/// <param name="phyPath">原图片的路径</param>
/// <param name="width">缩略图宽</param>
/// <param name="height">缩略图高</param>
/// <returns></returns>
public static string GetThumbnail(string phyPath, int width, int height)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(phyPath);
int orignWidth = image.Width; //原图尺寸
int orignHeight = image.Height;
float toWidth = (float)width; //缩略图目标尺寸
float toHeight = (float)height;
float radio = (float)orignWidth / (float)orignHeight; //宽高比例
if (orignWidth >= orignHeight)
{ //宽度不变
toHeight = toWidth / radio;
}
else
{ //高度不变
toWidth = toHeight * radio;
}
System.Drawing.Image thumbImage = image.GetThumbnailImage(Convert.ToInt32(toWidth), Convert.ToInt32(toHeight), null, IntPtr.Zero);
string folder = Path.GetDirectoryName(phyPath);
string fileName = "\\s_" + Path.GetFileName(phyPath);
string savePath = folder + fileName;
try
{
thumbImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
image.Dispose();
thumbImage.Dispose();
}
return savePath;
}
试试这个
/// 为图片生成缩略图
/// </summary>
/// <param name="phyPath">原图片的路径</param>
/// <param name="width">缩略图宽</param>
/// <param name="height">缩略图高</param>
/// <returns></returns>
public static string GetThumbnail(string phyPath, int width, int height)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(phyPath);
int orignWidth = image.Width; //原图尺寸
int orignHeight = image.Height;
float toWidth = (float)width; //缩略图目标尺寸
float toHeight = (float)height;
float radio = (float)orignWidth / (float)orignHeight; //宽高比例
if (orignWidth >= orignHeight)
{ //宽度不变
toHeight = toWidth / radio;
}
else
{ //高度不变
toWidth = toHeight * radio;
}
System.Drawing.Image thumbImage = image.GetThumbnailImage(Convert.ToInt32(toWidth), Convert.ToInt32(toHeight), null, IntPtr.Zero);
string folder = Path.GetDirectoryName(phyPath);
string fileName = "\\s_" + Path.GetFileName(phyPath);
string savePath = folder + fileName;
try
{
thumbImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
image.Dispose();
thumbImage.Dispose();
}
return savePath;
}
试试这个
展开全部
aspjpeg本身不能上传图片,可以使用无惧上传等文件上传类。
生成缩略图的代码如下
<%
' Create instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Open source image
Jpeg.Open "c:\path\myimage.jpg"
' New width
L = 100
' Resize, preserve aspect ratio
Jpeg.Width = L
Jpeg.Height = Jpeg.OriginalHeight * L / Jpeg.OriginalWidth
' create thumbnail and save it to disk
Jpeg.Save "c:\path\thumbnail.jpg"
%>
生成缩略图的代码如下
<%
' Create instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Open source image
Jpeg.Open "c:\path\myimage.jpg"
' New width
L = 100
' Resize, preserve aspect ratio
Jpeg.Width = L
Jpeg.Height = Jpeg.OriginalHeight * L / Jpeg.OriginalWidth
' create thumbnail and save it to disk
Jpeg.Save "c:\path\thumbnail.jpg"
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询