商业源码热门下载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="";
}
新闻热点
疑难解答
图片精选