国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 阳原县| 佳木斯市| 岳普湖县| 漾濞| 崇明县| 塘沽区| 新乡市| 彭泽县| 年辖:市辖区| 三明市| 株洲县| 报价| 游戏| 怀柔区| 达拉特旗| 安远县| 道真| 息烽县| 手游| 宣威市| 陈巴尔虎旗| 广宁县| 斗六市| 衡东县| 英吉沙县| 辽宁省| 平塘县| 丹寨县| 开远市| 重庆市| 响水县| 宜兰市| 盘山县| 清镇市| 施甸县| 平和县| 潼关县| 阿巴嘎旗| 彭泽县| 阜新市| 固安县|