网上摸索,自己修改实现上传图片的功能
2016-10-14 09:10
585 查看
实现上传图片功能;
protected void Button1_Click(object sender, EventArgs e) { //判断上传控件中是否有值 if (FileUpimage.HasFile == false) { Response.Write(""); } else { string fType = FileUpimage.PostedFile.ContentType;//获取图像的类型 if (fType == "image/bmp" || fType == "image/gif" || fType == "image/pjpeg" || fType == "image/jpeg" || fType == "image/png") { //获取文件信息 FileInfo file = new FileInfo(FileUpimage.PostedFile.FileName); ///随机数据 Guid guid = Guid.NewGuid(); string stamp = guid.ToString("N"); //生成随机数 Random aa = new Random(); string number = aa.Next(10000).ToString(); //原始图片保存路径 string path = "~/Fileupimage/" + stamp + ".gif"; //缩略图保存路径 string spath = "~/Fileupimage/" + number + ".gif"; try { //原始图片保存 FileUpimage.SaveAs(Server.MapPath(path)); //字体图片保存 Draw(Server.MapPath(path),Server.MapPath(spath)); //缩略图保存 //MakeThumbImage(Server.MapPath(path), Server.MapPath(spath), 200, 100); //给隐藏的图片控件赋值并显示 Image1.Visible = true; Image1.ImageUrl = spath; Response.Write(""); } catch { Response.Write(""); } } else { Response.Write(""); } } } /// ///创建日期:2016-10-14 ///创建人 :ss ///方法名称:MakeThumbImage ///内容摘要:生成缩略图,或者在图片上写字 /// /// 源图路径(物理路径) /// 缩略图路径(物理路径) /// 缩略图宽度 /// 缩略图高度 private void MakeThumbImage(string sPath, string stPath, int nWidth, int nHeight) { System.Drawing.Image sImage = System.Drawing.Image.FromFile(sPath); int tw = nWidth; int th = nHeight; ///原始图片的宽度和高度 int sw = sImage.Width; int sh = sImage.Height; if (sw > tw) { sw = tw; } if (sh > th) { sh = th; } System.Drawing.Bitmap objPic, objNewPic; objPic = new System.Drawing.Bitmap(sPath); objNewPic = new System.Drawing.Bitmap(objPic, sw, sh); objNewPic.Save(stPath); sImage.Dispose(); objPic.Dispose(); objNewPic.Dispose(); } public void Draw(string path,string stpath) { System.Drawing.Image image = System.Drawing.Image.FromFile(path) ;// 具体这张图是从文件读取还是从picturebox什么的获取你来指定 using (Graphics g = Graphics.FromImage(image)) { g.DrawString(TextBox1.Text, new Font("隶书", 23), Brushes.Red, new PointF(0, 0)); g.Flush(); } image.Save(stpath); }
相关文章推荐
- 上传图片|修改上传图片的功能实现
- Python的Tornado框架实现图片上传及图片大小修改功能
- Python的Tornado框架实现图片上传及图片大小修改功能
- kindeditor 修改jsp中的图片上传功能
- 自己动手写ORM框架(八):实现修改功能Update方法
- ASP.Net中使用FreeTextBox图片上传功能的修改(点上传直接返回编辑器显示图片)
- 上传图片功能的又一实现
- 一个实现图片上传/产生缩略图/在上传图片上写字功能的完整页面代码
- ASP上传图片功能的又一实现(OLE对象)
- Flex中使用RemoteObject实现图片上传功能
- SilvetLight 实现的一个上传图片时功能动态裁剪部分区域和缩放图片的功能
- 实现sharepoint 内容编辑器直接上传图片功能
- 图片上传和修改最短的代码实现~
- ASP上传图片至数据库内功能的实现
- swfupload+json+struts2实现多图片上传功能(一)
- 在asp.Net中使用fileuplod控件实现上传图片的功能
- 自己尝试实现的文件上传功能,未用其他组件
- hchxxzx--》一个实现图片上传/产生缩略图/在上传图片上写字功能的完整页面代码
- Spring MVC 实现图片上传功能
- 如何实现 asp 上传产品图片加水印功能