欢迎光临
我们一直在努力

如何在上传的图片上写字-.NET教程,数据库应用

建站超值云服务器,限时71元/月

很多时候需要在用户上传的图片上加上版权或者一些其他的附加文字信息,如何实现这样的功能,下面帖个简单实现的例子,起到抛砖引玉的作用。

<%@ 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!" 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>

文本标题: <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/>

</asp:panel>

</form>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何在上传的图片上写字-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章