About the picture to send watermark ~~

xiaoxiao2021-03-06  42

Idea: Call GDI during the process of uploading the image, create a Bitmap object, read into the original picture and the watermark image in this object, then save it as a new picture .code: if (UploadFile.postedFile.FileName.trim ()! = "") {// Upload file string extension = path.Getextension (UploadFile.PostedFile.FileName) .toupper (); string filename = DATETIME.NOW.Year.Tostring () DateTime.now.month.tostring () " .Now.day.tostring () DATETIME.NOW.HOUR.TOSTRING () DATETIME.NOW.MINUTE.TOSTRING () DATETE.NOW.SECONTOSTOSTRING (); string path = server.mAppath (".") "/ Uploadfile /" filename extension; uploadfile.postedfile.saveas (path);

// add text watermark, note that the code here is below the picture watermark code cannot coexist system.drawing.image.FromFile (path); graphics g = graphics.FromImage (image); g. DrawImage (image, image.height); font f = new font ("Verdana", 32); brush b = new solidbrush (color.white); string addtext = addtext.value.trim ); G.drawstring (AddText, F, B, 10, 10); g.dispose ();

// Plus pictures Water-print System.drawing.Image Image = system.drawing.image.fromfile (path); system.drawing.image.fromfile (Server.mAppath ("(") "/ alex .gif "); Graphics g = Graphics.FromImage (image); g.DrawImage (copyImage, new Rectangle (image.Width-copyImage.Width, image.Height-copyImage.Height, copyImage.Width, copyImage.Height), 0 , 0, copyimage.height, graphicsunit.pixel); g.dispose (); // Save the post-plated picture, delete the original picture string newpath = server.mappath (".") "/ Uploadfile / " FileName " _new " extension; image.save (newPath); IMAGE.Dispose (); if (file.exists (path)) {file.delete (PATH);

Response.redirect (newpath);

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

New Post(0)