有一些图片,在上传生成缩略图时候会变的很模糊,有一些又不会(但也不 是很清新).
后来我发现 从Photoshop 中导出的图片就会变模糊,而同一张图片在 Firework 中导出就不会.
很奇怪,,,,,,我导出的格式,尺寸等等所有的属性都一样啊,为什么会这样????
请教高手帮忙解答一下,。,!!!! 以下是我的代码片段。 HttpFileCollection hfc = this.Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i]; string f_name = System.IO.Path.GetFileName(hpf.FileName); #region 生成缩略图 //生成原图
System.IO.Stream oStream = hpf.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream); int oWidth = oImage.Width; //原图宽度
int oHeight = oImage.Height; //原图高度
int tWidth = 124; //设置缩略图初始宽度
int tHeight = 100; //设置缩略图初始高度
int aWidth = 700; //设置单张照片浏览的缩略图宽度
int aHeight = oHeight; //设置单张照片浏览的缩略图高度 //按比例计算出缩略图的宽度和高度
if (oWidth <= 700)
{
aWidth = oWidth;
aHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(aWidth) / Convert.ToDouble(oWidth)));
}
else
{
aWidth = 700;
aHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(aWidth) / Convert.ToDouble(oWidth)));
} string oFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + oxxx; //保存原图的物理路径
string tFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + txxx; //保存缩略图的物理路径
string aFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + axxx; //保存单张照片浏览的缩略图的物理路径 System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack); //生成缩略图
System.Drawing.Image tImage = oImage.GetThumbnailImage(tWidth, tHeight, myCallback, IntPtr.Zero);
System.Drawing.Image aImage = oImage.GetThumbnailImage(aWidth, aHeight, myCallback, IntPtr.Zero); hpf.SaveAs(Server.MapPath("~/images/upload/" + useralbumfile + "/" + albumname + "/") + ofilename);
{
//释放资源
tImage.Dispose();
aImage.Dispose();
} private bool ThumbnailCallBack()
{
return false;
}
后来我发现 从Photoshop 中导出的图片就会变模糊,而同一张图片在 Firework 中导出就不会.
很奇怪,,,,,,我导出的格式,尺寸等等所有的属性都一样啊,为什么会这样????
请教高手帮忙解答一下,。,!!!! 以下是我的代码片段。 HttpFileCollection hfc = this.Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i]; string f_name = System.IO.Path.GetFileName(hpf.FileName); #region 生成缩略图 //生成原图
System.IO.Stream oStream = hpf.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream); int oWidth = oImage.Width; //原图宽度
int oHeight = oImage.Height; //原图高度
int tWidth = 124; //设置缩略图初始宽度
int tHeight = 100; //设置缩略图初始高度
int aWidth = 700; //设置单张照片浏览的缩略图宽度
int aHeight = oHeight; //设置单张照片浏览的缩略图高度 //按比例计算出缩略图的宽度和高度
if (oWidth <= 700)
{
aWidth = oWidth;
aHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(aWidth) / Convert.ToDouble(oWidth)));
}
else
{
aWidth = 700;
aHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(aWidth) / Convert.ToDouble(oWidth)));
} string oFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + oxxx; //保存原图的物理路径
string tFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + txxx; //保存缩略图的物理路径
string aFullName = Server.MapPath("~/images/upload/" + xxxx+ "/" + xxxx+ "/") + axxx; //保存单张照片浏览的缩略图的物理路径 System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallBack); //生成缩略图
System.Drawing.Image tImage = oImage.GetThumbnailImage(tWidth, tHeight, myCallback, IntPtr.Zero);
System.Drawing.Image aImage = oImage.GetThumbnailImage(aWidth, aHeight, myCallback, IntPtr.Zero); hpf.SaveAs(Server.MapPath("~/images/upload/" + useralbumfile + "/" + albumname + "/") + ofilename);
{
//释放资源
tImage.Dispose();
aImage.Dispose();
} private bool ThumbnailCallBack()
{
return false;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货