




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;public partial class upfile_upfi
2、le : System.Web.UI.Pageprotected void Page_Load(object sender, EventArgs e protected void Button1_Click(object sender, EventArgs eif (FileUpload1.HasFilestring fileContentType = FileUpload1.PostedFile.ContentType;if (fileContentType = image/bmp | fileContentType = image/gif | fileContentType = image
3、/pjpegstring name = FileUpload1.PostedFile.FileName; / 客戶端文件路徑FileInfo file = new FileInfo(name;string fileName = file.Name; / 文件名稱string fileName_s = s_ + file.Name; / 縮略圖文件名稱string fileName_sy = sy_ + file.Name; / 水印圖文件名稱(文字)string fileName_syp = syp_ + file.Name; / 水印圖文件名稱(圖片)string webFilePath =
4、 Server.MapPath(file/ + fileName; / 服務(wù)器端文件路徑string webFilePath_s = Server.MapPath(file/ + fileName_s;/ 服務(wù)器端縮略圖路徑string webFilePath_sy = Server.MapPath(file/ + fileName_sy;/ 服務(wù)器端帶水印圖路徑(文字string webFilePath_syp = Server.MapPath(file/ + fileName_syp;/ 服務(wù)器端帶水印圖路徑(圖片string webFilePath_sypf = Server.MapPa
5、th(file/shuiyin.jpg;/ 服務(wù)器端水印圖路徑(圖片if (!File.Exists(webFilePathtryFileUpload1.SaveAs(webFilePath; / 使用 SaveAs 方法保存文件AddShuiYinWord(webFilePath, webFilePath_sy;AddShuiYinPic(webFilePath, webFilePath_syp, webFilePath_sypf;MakeThumbnail(webFilePath, webFilePath_s, 130, 130, Cut; / 生成縮略圖方法Label1.Text = 提
6、示:文件“ + fileName + ”成功上傳,并生成“ + fileName_s + ”縮略圖,文件類型為: + FileUpload1.PostedFile.ContentType + ,文件大小為: + FileUpload1.PostedFile.ContentLength + B;catch (Exception exLabel1.Text = 提示:文件上傳失敗,失敗原因: + ex.Message;elseLabel1.Text = 提示:文件已經(jīng)存在,請重命名后上傳;elseLabel1.Text = 提示:文件類型不符;/ / 生成縮略圖/ / 源圖路徑(物理路徑)/ 縮略
7、圖路徑(物理路徑)/ 縮略圖寬度/ 縮略圖高度/ 生成縮略圖的方式 public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string modeSystem.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath;int towidth = width;int toheight = height;int x = 0;int y = 0;int
8、ow = originalImage.Width;int oh = originalImage.Height;switch (modecase HW:/指定高寬縮放(可能變形) break;case W:/指定寬,高按比例 toheight = originalImage.Height * width / originalImage.Width;break;case H:/指定高,寬按比例towidth = originalImage.Width * height / originalImage.Height;break;case Cut:/指定高寬裁減(不變形) if (doubleorig
9、inalImage.Width / (doubleoriginalImage.Height (doubletowidth / (doubletoheightoh = originalImage.Height;ow = originalImage.Height * towidth / toheight;y = 0;x = (originalImage.Width - ow / 2;elseow = originalImage.Width;oh = originalImage.Width * height / towidth;x = 0;y = (originalImage.Height - oh
10、 / 2;break;default:break;/新建一個(gè)bmp圖片System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight;/新建一個(gè)畫板System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap;/設(shè)置高質(zhì)量插值法g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;/設(shè)置高質(zhì)量,低速度呈現(xiàn)平滑程度g.SmoothingMode = Sy
11、stem.Drawing.Drawing2D.SmoothingMode.HighQuality;/清空畫布并以透明背景色填充g.Clear(System.Drawing.Color.Transparent;/在指定位置并且按指定大小繪制原圖片的指定部分g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight,new System.Drawing.Rectangle(x, y, ow, oh,System.Drawing.GraphicsUnit.Pixel;try/以jpg格式保存縮略圖bi
12、tmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg;catch (System.Exception ethrow e;finallyoriginalImage.Dispose(;bitmap.Dispose(;g.Dispose(;/ / 在圖片上增加文字水印/ / 原服務(wù)器圖片路徑/ 生成的帶文字水印的圖片路徑protected void AddShuiYinWord(string Path, string Path_systring addText = 測試水印;System.Drawing.Image imag
13、e = System.Drawing.Image.FromFile(Path;System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image;g.DrawImage(image, 0, 0, image.Width, image.Height;System.Drawing.Font f = new System.Drawing.Font(Verdana, 16;System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Blue;g
14、.DrawString(addText, f, b, 15, 15;g.Dispose(;image.Save(Path_sy;image.Dispose(;/*/ / 在圖片上生成圖片水印/ / 原服務(wù)器圖片路徑/ 生成的帶圖片水印的圖片路徑/ 水印圖片路徑protected void AddShuiYinPic(string Path, string Path_syp, string Path_sypfSystem.Drawing.Image image = System.Drawing.Image.FromFile(Path;System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf;System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image;g.DrawImage(copyImage, new System.Drawing.R
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 藥物研究的多學(xué)科協(xié)作模式探討試題及答案
- 系統(tǒng)架構(gòu)設(shè)計(jì)師考試職場軟技能的重要性試題及答案
- 系統(tǒng)架構(gòu)設(shè)計(jì)師考試復(fù)雜性應(yīng)對策略及試題答案
- 光電工程師考試復(fù)習(xí)要點(diǎn)與試題
- 藝術(shù)設(shè)計(jì)考研試題及答案
- 提升考試能力的網(wǎng)絡(luò)規(guī)劃設(shè)計(jì)師試題及答案
- 2025-2030寵物保健品行業(yè)規(guī)模預(yù)測與投資前景策略建議分析研究報(bào)告
- 2025-2030天津市軌道交通行業(yè)市場發(fā)展分析及發(fā)展前景與投資研究報(bào)告
- 2025-2030國內(nèi)纖維素行業(yè)市場發(fā)展分析及競爭格局與投資機(jī)會研究報(bào)告
- 2025-2030國內(nèi)消防設(shè)備行業(yè)市場發(fā)展分析及競爭格局與投資前景研究報(bào)告
- 2025年高壓電工作業(yè)考試國家總局題庫及答案(共280題)
- 家庭農(nóng)場經(jīng)營與管理培訓(xùn)課件
- 中國重癥腦血管病管理共識課件
- 轉(zhuǎn)爐煉鋼設(shè)備與工藝課件
- 汽車吊車施工安全技術(shù)交底
- 電工基礎(chǔ)(中職)完整版教學(xué)課件
- 小班語言繪本《小蛇散步》繪本PPT
- 杭州房建工程監(jiān)理大綱范本
- DB22∕T 2797.1-2017 玄武巖纖維復(fù)合筋及玄武巖纖維混凝土設(shè)計(jì)與施工規(guī)范 第1部分:玄武巖纖維復(fù)合筋
- 慶陽剪紙藝術(shù):演示文稿
- 人居環(huán)境學(xué)導(dǎo)論
評論
0/150
提交評論