51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> asp.net >> 文章正文

asp.net上传图片自动生成缩略图功能代码

更新时间:2012-2-16:  来源:51代码网

Graphics g = Graphics.FromImage(tImage);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空画布并以透明背景色填充
g.Clear(Color.Transparent);
g.DrawImage(oImage, new Rectangle(0, 0, tWidth, tHeight), new Rectangle(0, 0, oWidth, oHeight), GraphicsUnit.Pixel);

string fullFileName = this.FileUpload1.PostedFile.FileName.ToString();
fullFileName = fullFileName.Remove(fullFileName.LastIndexOf('.'));
string filename = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
//存储路径
string strLocation = path.ToString();
string tFullName = strLocation + Session["WorkingImage"].ToString();
try
{
// 上传缩略
tImage.Save(tFullName, System.Drawing.Imaging.ImageFormat.Jpeg);
//输出上传成功提示并显示保存路径
TextBox3.Text = "uploadfiles/product/" + Session["WorkingImage"].ToString();
// pic_upload.Visible = false;
// pic_crop.Visible = true;
// 读取缩略图
path = "../uploadfiles/product/" + Session["WorkingImage"].ToString();

}
catch (Exception)
{
Response.Write("<script language=javascript>alert('上传失败,请重试!');window.location.href=window.location.href;</script>");
}
finally
{
//释放资源
oImage.Dispose();
g.Dispose();
tImage.Dispose();
}
}
catch (Exception)
{
Response.Write("<script language=javascript>alert('上传失败,请重试!');window.location.href=window.location.href;</script>");
}}}

上一页  [1] [2] 

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |