Put the upload picture to the anti-counterfeiting picture watermark and write to the database

xiaoxiao2021-03-06  46

/ * Author: Sharpcn | Scorpion Studio: www.bkwww.com Copyright (C) Manta Home Function: Add an uploaded picture to the anti-counterfeiting picture, and write pictures directly to the database, not retained on the hard disk. * /

// involving namespace 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;

// Water print ------------------------------------------------------------------------------------------------------------------------------------ --------------> String WimageFile = Server.mappath ("/ bkwww / image / homesign.gif"); // To add watermark image image simage = image.fromstream (imageStream) ; // Create image image wiMage = image.fromfile from the HTTP input stream;

// Draw 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, translate image to byte [] MemoryStream ms = new memoryStream (); byte [] MyImage = null; simage.save (ms, imageformat.gif); myimage = ms.getBuffer (); // -------------------------------------------------- ---------------->

// write 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 ());}}

转载请注明原文地址:https://www.9cbs.com/read-110118.html

New Post(0)