Upload | upload pictures | data | database *
AUTHOR:SHARPCN | Scorpion
Studio:www.bkwww.com
Copyright (c) 2004 Home tomorrow
Function: Will upload the picture to add security image watermark, and the picture directly written to the database, do not keep on the hard disk.
*/
involving namespaces
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;
Method
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;
Add Watermark------------------------------------------------------------>
String wimagefile = Server.MapPath ("/bkwww/image/homesign.gif"); To add a watermark map
Image simage = Image.fromstream (ImageStream); Create an image from an Http input stream
Image wimage = Image.FromFile (wimagefile);
Drawing
Graphics g = graphics.fromimage (simage);
G.drawimage (Wimage, New Rectangle (0, 0, Wimage.width, wimage.height), 0, 0, wimage.width, Wimage.height, GraphicsUnit.Pixel);
Save, and convert image to byte[]
MemoryStream ms=new MemoryStream ();
Byte[] Myimage=null;
Simage.save (MS, Imageformat.gif);
MyImage = Ms. GetBuffer ();
------------------------------------------------------------------>
Writing to the database
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 ("Add success!") ");
}
catch (System.Exception Sqlex)
{
Response.Write ("Add failed!") "+sqlex.tostring ());
}
}