Upload the picture and display the image

xiaoxiao2021-03-06  37

private void Button1_Click (object sender, System.EventArgs e) {if (File1.PostedFile.FileName = null!) {string namestr = Path.GetFileName (File1.PostedFile.FileName); // file name to extract the File1.PostedFile.SaveAs ( Server.mappath (".") @ "/" Namestr); image2.visible = true; image2.imageurl = server.mappath (".") @ "/" Namestr; system.drawing.Image Image, aNewImage; image = System.Drawing.Image.FromStream (File1.PostedFile.InputStream); decimal width = image.Width; decimal height = image.Height; int newwidth, newheight; if (width> height) {newwidth = 150; newheight = (int) (height / width * 150);} else {newheight = 150; newwidth = (int) (width / height * 150);} aNewImage = image.GetThumbnailImage (newwidth, newheight, null, IntPtr.Zero); Bitmap output = new bitmap (anewimage); graphics g = graphics.fromimage (output); g.drawstring (TextBox1.Text.trim (), New Font ("Courier New", 9), New Solidbrush (Color.red), 60, 60); // Write copyright information and text format and location Output.save (Server.mappath (".") @ "/ S _" namestr, system.drawing. Imaging.imageformat.jpeg); image1.visible = true; image1.imageurl = server.mappath (".") @ "/ S _" namestr;}}

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

New Post(0)