网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.使用ASP.NET2.0的ReportViewer查.
.关于ASP.NET2.0编写扩展存储过程.
.asp.net的一个bug的发现和解决.
.ASP.NET里常用的JS.
.Asp.Net中NHiernate的Session的管.
.用window.location.href实现刷新.
..Net开发漫谈:关于命名空间和目.
.ASP.NET 2.0服务器控件开发精要.
..net2.0中使用SqlBulkCopy进行大.
.在ASP.NET中跨页面实现多选.
.如何实现无刷新的DropdownList联.
.ASP.NET 2.0中的Web和HTML服务器.
.asp.net2.0中关于ASP.NET 网站管.
.URL重写可删节日期模式---正则表.
.中国地区三级联动下拉菜单代码和.
.为Serv-U提供在线修改密码功能 .
.SQL Artisan多表查询和统计.
.根据xsd生成xml文档.
.动态创建MSSQL数据库表存储过程.
.ASP.NET中备份SQL Server数据库的.

如何在上传的图片上写字

发表日期:2004-11-3


很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。
<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
      void UploadBtn_Click(Object sender, EventArgs e) {
        String filename;
        String filename1;
        String[] filename2;
        int q;
        filename=UploadFile.PostedFile.FileName ;
        filename2=filename.Split(new Char[] {'\\'});
        q=filename2.GetUpperBound(0);
        filename1=filename2[q];
        dis.Text="上传文件名:"+filename1+"<br>";
        UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
        ImageEditor.Visible = true;
        dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
        Image1.Src=filename1;     
      }
      void UpdateBtn_Click(Object sender, EventArgs e) {
        String filename1;
        filename1=Image1.Src;
        System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
        System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
        Graphics g = Graphics.FromImage(newimage);
        g.DrawImage(image,0,0,image.Width,image.Height);
        Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
        Brush b = new SolidBrush(Color.Red);
        g.DrawString(Caption.Text, f, b, 10, 140);
        g.Dispose();
        System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse
(Height.Text),null,0);
        image.Dispose();
        thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG);
        Image1.Src=filename1;     
        Caption.Text="";   
 
      }

  </script>

  <body>
  <asp:label id="dis" runat=server/>
    <form enctype="multipart/form-data" runat=server>
          选择上传文件: <input id="UploadFile" type=file runat=server>
          <asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/>
          <hr>
          <asp:panel id="ImageEditor" Visible=false runat=server>
            <img ID="Image1" src="" runat="server"/>
                图像宽度: <asp:textbox id="Width" runat=server/>
                图像高度: <asp:textbox id="Height" runat=server/> <br>
                文本标题: <asp:textbox id="Caption" runat=server/>
                标题字号: <asp:dropdownlist id="FontSize" runat=server>
                                        <asp:listitem>14</asp:listitem>
                                        <asp:listitem>18</asp:listitem>
                                        <asp:listitem>26</asp:listitem>
                                        <asp:listitem>36</asp:listitem>
                                        <asp:listitem>48</asp:listitem>
                                        <asp:listitem>62</asp:listitem>
                                      </asp:dropdownlist>
                标题字体: <asp:dropdownlist id="FontType" runat=server>
                                        <asp:listitem>黑体</asp:listitem>
                                        <asp:listitem>仿宋</asp:listitem>
                                        <asp:listitem>隶书</asp:listitem>
                                        <asp:listitem>楷书</asp:listitem>
                                        <asp:listitem>彩云</asp:listitem>
                                        <asp:listitem>新魏</asp:listitem>
                                      </asp:dropdownlist>
                                               
                <asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/>
          </asp:panel>
      </form>

  </body>
</html>

上一篇:在ASP.NET程序中创建唯一序号 人气:12730
下一篇:原创的自定义分页UserControl 分享及探讨 人气:12488
浏览全部上传的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐