




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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; / 服务器端文件路径string webFilePath_s = Server.MapPath(file/ + fileName_s;/ 服务器端缩略图路径string webFilePath_sy = Server.MapPath(file/ + fileName_sy;/ 服务器端带水印图路径(文字string webFilePath_syp = Server.MapPath(file/ + fileName_syp;/ 服务器端带水印图路径(图片string webFilePath_sypf = Server.MapPa
5、th(file/shuiyin.jpg;/ 服务器端水印图路径(图片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 = 提示:文件已经存在,请重命名后上传;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;/新建一个bmp图片System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight;/新建一个画板System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap;/设置高质量插值法g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;/设置高质量,低速度呈现平滑程度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(;/ / 在图片上增加文字水印/ / 原服务器图片路径/ 生成的带文字水印的图片路径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(;/*/ / 在图片上生成图片水印/ / 原服务器图片路径/ 生成的带图片水印的图片路径/ 水印图片路径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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (二模)衢州、丽水、湖州2025年4月三地市高三教学质量检测 地理试卷(含答案)
- 个人卖电梯合同样本
- 军方食谱采购合同样本
- 修剪树合同样本
- 中铁铁路施工合同样本
- 井维修合同样本
- 付款合同样本制作
- 农村药店采购合同标准文本
- 买卖生口合同样本
- 农村承包荒山合同标准文本
- 执业兽医机构聘用证明或服务协议
- 工资福利政策讲座
- 卓越绩效调研提纲
- 【经典】一次性使用氧气湿化瓶-一次性使用加湿型鼻氧管介绍教学课件
- Unit2HelpingEachOtherPartA(教学设计)闽教版英语六年级下册
- 危重患者护理质量管理查检表
- 2023年四川二造《建设工程造价管理基础知识》高频核心题库300题(含解析)
- 班主任的智慧与对策
- 细胞课件 细胞死亡
- 石灰石粉粉检测报告
- 部编版道德与法治六年级上册第二单元《我们是公民》大单元作业设计
评论
0/150
提交评论