国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net實(shí)現(xiàn)生成縮略圖及給原始圖加水印的方法示例

2024-07-10 13:32:40
字體:
供稿:網(wǎng)友

本文實(shí)例講述了asp.net實(shí)現(xiàn)生成縮略圖及給原始圖加水印的方法。分享給大家供大家參考,具體如下:

using System.IO;using System.Drawing.Imaging;private void Button1_ServerClick(object sender, System.EventArgs e) {  Graphics g=null;  System.Drawing.Image upimage=null;  System.Drawing.Image thumimg=null;  System.Drawing.Image simage=null;  Bitmap outputfile=null;  try   {    string extension = Path.GetExtension(File1.PostedFile.FileName).ToUpper();    string filename = DateTime.Now.ToString("yyyyMMddhhmmss");    string smallpath = Server.MapPath(".")+"/smallimg/";    string bigpath = Server.MapPath(".")+"/bigimg/";    int width,height,newwidth,newheight;    System.Drawing.Image.GetThumbnailImageAbort callb =new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);    if(!Directory.Exists(smallpath))    Directory.CreateDirectory(smallpath);    if(!Directory.Exists(bigpath))    Directory.CreateDirectory(bigpath);    Stream upimgfile = File1.PostedFile.InputStream;    string simagefile = Server.MapPath("a8logo.jpg"); //要加水印的文件    simage=System.Drawing.Image.FromFile(simagefile);    upimage= System.Drawing.Image.FromStream(upimgfile); //上傳的圖片    width = upimage.Width;    height = upimage.Height;    if(width>height)     {      newwidth=200;      newheight =(int)((double)height/(double)width * (double)newwidth);    } else     {      newheight=200;      newwidth=(int)((double)width/(double)height * (double)newheight);    }    thumimg = upimage.GetThumbnailImage(newwidth,newheight,callb,IntPtr.Zero);    outputfile=new Bitmap(upimage);    g=Graphics.FromImage(outputfile);    g.DrawImage(simage,new Rectangle(upimage.Width-simage.Width,upimage.Height-simage.Height,upimage.Width,upimage.Height),0,0,upimage.Width,upimage.Height,GraphicsUnit.Pixel);    string newpath = bigpath + filename + extension; //原始圖路徑    string thumpath = smallpath + filename + extension; //縮略圖路徑    outputfile.Save(newpath);    thumimg.Save(thumpath);    outputfile.Dispose();  }  catch(Exception ex)   {    throw ex;  }  finally   {    if(g!=null)    g.Dispose();    if(thumimg!=null)    thumimg.Dispose();    if(upimage!=null)    upimage.Dispose();    if(simage!=null)    simage.Dispose();  }}public bool ThumbnailCallback() {  return false;}

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到ASP.NET教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 黎川县| 镇雄县| 镇巴县| 盘锦市| 昌黎县| 特克斯县| 中阳县| 武汉市| 乐东| 本溪| 昭苏县| 达日县| 阿图什市| 长汀县| 台中县| 佛坪县| 临夏县| 广河县| 监利县| 久治县| 尤溪县| 临泽县| 太康县| 连平县| 竹山县| 炉霍县| 东乌| 灵石县| 喜德县| 板桥市| 图木舒克市| 饶平县| 普陀区| 北川| 鄂托克前旗| 文昌市| 文安县| 开封县| 固阳县| 九江市| 遂川县|