国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

如何在上傳的圖片上寫字

2019-11-17 05:50:11
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
很多時(shí)候需要在用戶上傳的圖片上加上版權(quán)或者一些其他的附加文字信息,如何實(shí)現(xiàn)這樣的功能,下面帖個(gè)簡(jiǎn)單實(shí)現(xiàn)的例子,起到拋磚引玉的作用。
<%@ 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+"字節(jié)數(shù)";
        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>
                文本標(biāo)題: <asp:textbox id="Caption" runat=server/>
                標(biāo)題字號(hào): <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>
                標(biāo)題字體: <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>


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 常山县| 巴彦淖尔市| 溧水县| 定陶县| 凉城县| 墨江| 镇坪县| 渭南市| 苍山县| 高雄县| 安福县| 察哈| 东源县| 定南县| 洪江市| 元阳县| 绥德县| 砚山县| 扶绥县| 葫芦岛市| 扎鲁特旗| 盈江县| 七台河市| 芷江| 吉水县| 横峰县| 丹棱县| 景宁| 石林| 图木舒克市| 西吉县| 同江市| 嵊泗县| 承德县| 遵化市| 怀化市| 富顺县| 仪陇县| 宁强县| 鹤山市| 汤阴县|