Username: Password:

将上传图片打上防伪图片水印并写入数据库-ASP教程,数据库相关
来源:作者: 发布时间:2007-12-26 02:08:09

// 涉及命名空间
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.appsettings["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());
}
}

/*
www.knowsky.com
author: sharpcn | scorpion
studio: www.bkwww.com
copyright(c) 2004 明天家园
function:将上传的图片添加防伪图片水印,并将图片直接写入数据库,不保留在硬盘。
*/


喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅