最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net中上传图片文件实例(给上传图片加水印)
时间:2022-06-25 06:10:56 编辑:袖梨 来源:一聚教程网
本款asp教程.net教程是一款asp.net教程中上传图片文件实例(给上传图片加水印)哦,他先是把图片上传服务器,然后增加图片水印,再把图片保存到数据库教程。
// 涉及命名空间
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.data.sqlclient;
using system.drawing;
using system.drawing.drawing2d;
using system.drawing.imaging;
using system.web;
using system.configuration;// 方法
public void adduser(string personname, string personemail, string personsex, string persondob, string personimage, string personimagetype)
{
string strimagetype = userimage.postedfile.contenttype;
stream imagestream = userimage.postedfile.inputstream;// 加水印----------------->
string wimagefile = server.mappath("/bkwww/image/homesign.gif"); // 要加的水印图
image simage = image.fromstream(imagestream); // 从 http 输入流创建 image
image wimage = image.fromfile(wimagefile);// 绘图
graphics g = graphics.fromimage(simage);
g.drawimage(wimage, new rectangle(0, 0, wimage.width, wimage.height), 0, 0, wimage.width, wimage.height, graphicsunit.pixel);// 保存,并将 image 转化为 byte[]
memorystream ms=new memorystream();
byte[] myimage=null;
simage.save(ms, imageformat.gif);
myimage = ms.getbuffer();
//------------------------>
// 写入数据库
string strconn = configurationsettings.apps教程ettings["connectionstring"];
sqlconnection myconnection = new sqlconnection(strconn);
sqlcommand mycommand = new sqlcommand("sp_person_isp", myconnection);
mycommand.commandtype = commandtype.storedprocedure;mycommand.parameters.add("@personemail", sqldbtype.varchar, 255).value = personemail;
mycommand.parameters.add("@personname", sqldbtype.varchar, 255).value = personname;
mycommand.parameters.add("@personsex", sqldbtype.char, 1);
if(sexmale.checked)
mycommand.parameters["@personsex"].value = "m";
else
mycommand.parameters["@personsex"].value = "f";
mycommand.parameters.add("@persondob", sqldbtype.datetime).value = persondob;
mycommand.parameters.add("@personimage", sqldbtype.image).value = myimage;
mycommand.parameters.add("@personimagetype", sqldbtype.varchar, 255).value = imagetype;try
{
myconnection.open();
mycommand.executenonquery();
myconnection.close();
response.write("添加成功!");
}
catch(system.exception sqlex)
{
response.write("添加失败!"+sqlex.tostring());
}
}
相关文章
- 录音机app哪个好 热门的录音软件推荐 07-06
- 免费换图标app下载 热门的图片编辑软件分享 07-06
- 田园生活模拟游戏静谧田园中文版确定7月同步在亚洲推出 07-06
- 飞机票选座位的app推荐 飞机票选座位的软件哪款更好用 07-06
- 儿童英语启蒙app哪个好 好用儿童英语启蒙app推荐 07-06
- 会议纪要录音转文字软件免费推荐 - 会议纪要录音转文字软件免费有哪些 07-06