如何在上傳的圖片上加上著作權文字

來源:互聯網
上載者:User
上傳

很多時候需要在使用者上傳的圖片上加上著作權或者一些其他的附加文字資訊,如何?這樣的功能,下面帖個簡單實現的例子,起到拋磚引玉的作用。
<%@ 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!" 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" runat=server/>
          </asp:panel>
      </form>

  </body>
</html>



很多時候需要在使用者上傳的圖片上加上著作權或者一些其他的附加文字資訊,如何?這樣的功能,下面帖個簡單實現的例子,起到拋磚引玉的作用。
<%@ 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!" 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" runat=server/>
          </asp:panel>
      </form>

  </body>
</html>





相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。