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

首頁 > 編程 > .NET > 正文

asp.net給圖片加水印

2024-07-10 13:06:16
字體:
來源:轉載
供稿:網友

商業源碼熱門下載www.html.org.cn

程序代碼
<html><title>如何在圖片上寫字</title>
<body>
  <asp:label id="dis" runat=server/>
  <form enctype="multipart/form-data" runat=server id="form1">
  選擇上傳文件:<input id="uploadfile" type=file runat=server name="uploadfile">
  <asp:button text="upload me!" onclick="uploadbtn_click" runat=server id="button1"/>
  <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"/>
  文本標題:<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" id="button2"/>
  </asp:panel>
</form>
</body>
</html> 

后臺代碼
說明:
1.加圖片和加文字不能共存的就是你只能用一種
2.加圖片的時候必須要保證你被加的水印的圖片3.png在(可以自己改其他,程序中也要改)
必須有這個存放圖片的文件夾,uploadfile(可以自己改其他,程序中也要改)
3.要改變文字,圖片的位置必須在程序中改.

 程序代碼
public 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.antiquewhite);
  //g.drawstring(caption.text, f, b, 100, 140);
  //g.dispose();
 
 
  //加圖片水印
  system.drawing.image image = system.drawing.image.fromfile(server.mappath(filename1));//原圖
  system.drawing.image newimage = system.drawing.image.fromfile( server.mappath("3.png"));//此對象為被加的水印圖
  graphics g = graphics.fromimage(image);
  g.drawimage(newimage, new rectangle(image.width-newimage.width, image.height-newimage.height, newimage.width, newimage.height), 0, 0, newimage.width, newimage.height, graphicsunit.pixel);
  g.dispose();
 
  //加文字水印
  //system.drawing.image thumbimage = newimage.getthumbnailimage(image.width,image.height,null,new intptr());
  //image.dispose();
  //thumbimage.save(server.mappath(filename1), imageformat.jpeg);
 
  //加圖片水印
  image.save(server.mappath("uploadfile/"+filename1));
 
 
  image1.src = filename1;
  caption.text="";
  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴忠市| 镇沅| 莱阳市| 历史| 巴林右旗| 西宁市| 高邮市| 荥阳市| 石家庄市| 奉节县| 浦东新区| 城口县| 眉山市| 洛扎县| 读书| 阳西县| 岳阳县| 虹口区| 长阳| 鹤庆县| 泰宁县| 紫阳县| 绥宁县| 车险| 镇雄县| 额济纳旗| 天祝| 岐山县| 堆龙德庆县| 凌海市| 宁阳县| 荆门市| 宁南县| 涟源市| 漯河市| 大城县| 衡山县| 图片| 民和| 共和县| 吉首市|