麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

asp.net實現生成縮略圖及給原始圖加水印的方法示例

2024-07-10 13:32:40
字體:
來源:轉載
供稿:網友

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

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;}

希望本文所述對大家asp.net程序設計有所幫助。


注:相關教程知識閱讀請移步到ASP.NET教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 性少妇chinesevideo | 亚洲精品成人久久久 | 亚洲四播房 | www.99热精品| 精品无吗乱吗av国产爱色 | 亚洲免费视 | 国产91一区二区三区 | 成人444kkkk在线观看 | 91久久久久 | www.guochanav.com| 天使萌一区二区三区免费观看 | 精品国产一区二区三区久久久 | 亚州欧美在线 | 国产品久久 | 第四色成人网 | 在线a毛片免费视频观看 | 色综合视频网 | 欧美一级无毛 | 亚洲成人福利电影 | 亚洲一区二区中文字幕在线观看 | 日本免费aaa观看 | 欧美一区在线观看视频 | 特级无码毛片免费视频尤物 | 国产精品成人一区二区三区电影毛片 | 国产三级a三级三级 | 成人男女啪啪免费观看网站四虎 | 极品国产91在线网站 | 国产91一区二区三区 | 欧美在线观看视频一区 | 伊人午夜 | 欧美成人免费一区二区三区 | av视在线| 国产午夜网 | 亚洲国产精品久久久久久久久 | 中文字幕视频在线播放 | 久久久久久久久久久久免费 | 黄色高清免费 | omofun 动漫在线观看 | 蜜桃网站在线 | 久久久久久亚洲国产精品 | 国产免费一级大片 |