This section of the ASP tutorial. NET tutorial is a asp.net tutorial upload picture file instance (to upload image watermark) Oh, he first upload the image server, and then add image watermark, and then save the picture to the database tutorial.
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.apps Tutorial 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 ("Add success!") ");
}
catch (System.Exception Sqlex)
{
Response.Write ("Add failed!") "+sqlex.tostring ());
}
}