首页 IP地址查询 | Alexa排名查询 | 手机归属地查询
设为首页 收藏本站
  • 网络编程网络编程
  • 软件编程软件编程
  • 数据库技术数据库技术
  • 编程学院
  • 业界资讯 业界资讯
  • 源码中心源码中心
  • 会员中心会员中心
  • 页面导航: 首页C#.net图形&界面 → asp.net上传图片并生成可带版权信息的缩略图

    asp.net上传图片并生成可带版权信息的缩略图

    发布:Basic365.com 发布日期:2006-09-18 字体:[增加 减小] 类型:转载

    <%@ page language="c#" responseencoding="gb2312" %>
    <%@ import namespace="system" %>
    <%@ import namespace="system.io" %>
    <%@ import namespace="system.drawing" %>
    <%@ import namespace="system.drawing.imaging" %>
    <script runat="server"> 
      
    void page_load(object sender, eventargs e)
    {
    if(!page.ispostback)
    {
    imgpreview.visible=false;
    }
    }
    void getthumbnailimage(int width,int height,string strinfo,int left,int right)
    {
    string file="uploads/"+uploadfile.postedfile.filename.substring(uploadfile.postedfile.filename.lastindexof('\\')+1);
    string newfile="uploads/"+uploadfile.postedfile.filename.substring(uploadfile.postedfile.filename.lastindexof('\\')+1)+".jpg";
    string stradd=strinfo;
    system.drawing.image oldimage = system.drawing.image.fromfile(server.mappath(file));
    system.drawing.image thumbnailimage =
    oldimage.getthumbnailimage(width, height,new system.drawing.image.getthumbnailimageabort(thumbnailcallback), intptr.zero);
    response.clear();
    bitmap output=new bitmap(thumbnailimage);
    graphics g=graphics.fromimage(output);
    g.drawstring(stradd,new font("courier new", 14),new solidbrush(color.red),left,right);
    output.save(server.mappath(newfile),system.drawing.imaging.imageformat.jpeg);
    response.contenttype = "image/gif";
    imgpreview.visible=true;
    imgpreview.imageurl=newfile;
    }
    bool thumbnailcallback()
    {
    return true;
    }
    void button_click(object sender, eventargs e)
    {
    int width,height,left,right;
    string straddinfo=txtaddinfo.text;
    width=int32.parse(txtwidth.text);
    height=int32.parse(txtheight.text);
    left=int32.parse(txtleft.text);
    right=int32.parse(txtright.text);
    if(!(uploadfile.postedfile.contentlength>0))
    {
    lblerrinfo.text="没有选择文件";
    }
    else
    {
    string path = server.mappath("./uploads/"+uploadfile.postedfile.filename.substring(uploadfile.postedfile.filename.lastindexof('\\')+1));
    if(file.exists(path))
    {
    lblerrinfo.text="已经有同名文件";
    }
    else
    {
    uploadfile.postedfile.saveas(path);
    getthumbnailimage(width,height,straddinfo,left,right);
    }
    }
    }
    </script>
    <html>
    <head>
    </head>
    <body>
    <form method="post" enctype="multipart/form-data" runat="server">
    <p>
    <input id="uploadfile" type="file" runat="server" />
    <asp:label id="lblerrinfo" runat="server" forecolor="red"></asp:label>
    </p>
    <p>
    width:<asp:textbox id="txtwidth" runat="server" width="40px">100</asp:textbox>
    height:<asp:textbox id="txtheight" runat="server" width="40px">150</asp:textbox>
    </p>
    <p>
    添加信息:<asp:textbox id="txtaddinfo" runat="server"> aspxboy.com</asp:textbox>
    </p>
    <p>
    信息位置:left:<asp:textbox id="txtleft" runat="server" width="40px">10</asp:textbox>
    right:<asp:textbox id="txtright" runat="server" width="40px">135</asp:textbox>
    </p>
    <p>
    <input id="button" type="button" value="上传生成所略图" onserverclick="button_click" runat="server" />
    </p>
    <p><asp:image id="imgpreview" runat="server"></asp:image>
    </p>
    <!-- insert content here -->
    </form>
    </body>
    </html> 

    Tags: 缩略图
    为配合网络严查,文章评论将关闭敬请谅解.
    同 类 文 章
    最 近 更 新
    热 点 排 行