asp.net實(shí)現(xiàn)生成縮略圖及給原始圖加水印的方法示例
本文實(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; }
更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net字符串操作技巧匯總》、《asp.net操作XML技巧總結(jié)》、《asp.net操作json技巧總結(jié)》、《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。
希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。
- ASP.NET簡(jiǎn)單好用功能齊全圖片上傳工具類(水印、縮略圖、裁剪等)
- asp.net上傳圖片并作處理水印與縮略圖的實(shí)例代碼
- asp.net文件上傳功能(單文件,多文件,自定義生成縮略圖,水印)
- ASP.Net 上傳圖片并生成高清晰縮略圖
- asp.net圖片上傳生成縮略圖的注意事項(xiàng)
- asp.net 上傳圖片并同時(shí)生成縮略圖的代碼
- ASP.NET實(shí)現(xiàn)上傳圖片并生成縮略圖的方法
- Asp.net 文件上傳類(取得文件后綴名,保存文件,加入文字水印)
- asp.net 添加水印的代碼(已測(cè)試)
- asp.net下GDI+的一些常用應(yīng)用(水印,文字,圓角處理)技巧
- asp.net如何在圖片上加水印文字具體實(shí)現(xiàn)
相關(guān)文章
.Net使用SuperSocket框架實(shí)現(xiàn)WebSocket前端
這篇文章介紹了.Net使用SuperSocket框架實(shí)現(xiàn)WebSocket前端,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01ASP.NET數(shù)據(jù)庫編程之處理文件訪問許可
ASP.NET數(shù)據(jù)庫編程之處理文件訪問許可...2006-09-09HttpWebRequest和HttpWebResponse用法小結(jié)
在每個(gè)系統(tǒng)出寫入報(bào)告錯(cuò)誤代碼(找個(gè)合理的理由,比如系統(tǒng)免費(fèi)升級(jí)) -> 自家服務(wù)器接收并處理錯(cuò)誤報(bào)告 -> 反饋用戶(解決掉BUG就行,不要太聲揚(yáng))2011-09-09在ASP.NET中支持?jǐn)帱c(diǎn)續(xù)傳下載大文件(ZT)源碼
這篇文章主要為大家介紹了在ASP.NET中如何做到支持?jǐn)帱c(diǎn)續(xù)傳下載大文件(ZT),需要的朋友可以參考下2014-07-07