Implement thumbnail

xiaoxiao2021-03-06  41

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using system.drawing.image;

Namespace Emeng.exam {///

/// thumbnail's summary description. /// public class thumbnail: system.Web.ui.page {protected system.web.ui.webcontrols.lab.ui.webcontrols.button button1;

Private void page_load (Object sender, system.eventargs e) {// Place user code here to initialize page label1.text = "

Easily implement thumbnail " in ASP.NET; button1.text = "Upload and display the thumbnail";

}

#REGION Web Form Designer Generated Code Override Protected Void OnInit (Eventargs E) {//// Codegen: This call is required for the ASP.NET Web Form Designer. //Initializecomponent();Base.oninit (E);

///

/// Designer supports the required method - do not use the code editor to modify the // / this method. /// private () {this.button1.click = new system.eventhandler (this.button1_click); this.load = new system.eventhandler (this.page_load);

} #endregion

Private void button1_click (object sender, system.eventargs e) {httpfilecollection myfilecoll = httpContext.current.request.files; httppostedfile mypostedfile = myfilecoll [0];

IF (MyPostedFile.conteType.toString (). TOLOWER (). IndexOf ("Image") <0) {response.write ("Invalid graphics format."); return;} getthumbnail (MyPostedFile.FileName, 100, 100, MyPostedFile.ContentType.ToString (), false, MyPostedFile.InputStream);} private System.Drawing.Imaging.ImageFormat GetImageType (object strContentType) {if ((strContentType.ToString () ToLower ().) == "image / pjpeg" ) {Return System.drawing.Imaging.ImageFormat.jpeg;} else IF (). TOLOWER ()) == "image / gif") {return system.drawing.image.imageformat.gif;} else IF ((StrContentType.toString (). TOLOWER ()) == "image / bmp") {return system.drawing.image.imageformat.bmp;} else f ((StrContentType.toString (). TOLOWER ()) == "image / TIFF") {return system.drawing.imaging.imageformat.tiff;} else f ((StrContentType.tostring (). TOLOWER ()) == "image / x-icon") {Return System.drawing.Image Else IF ((strContentType.tostring (). TOLOWER ()) == "image / x-png") {return system.drawing.image.imageformat.png;} ELSE IF ((StrContentType.toString (). TOLOWER ()) == "Image / X-EMF") {Return System.drawing.Imaging.ImageFormat.emf;} else f ((StrContentType.toString (). TOLOWER () ) == "image / x-exif") {return system.drawing.Imaging.imageformat.exif;} else f ((StrContentType.toString (). TOLOWER ()) == "image / x-wmf") {Return System.Drawing.Imaging.ImageFormat.Wmf;} else {return System.Drawing.Imaging.ImageFormat.MemoryBmp;}} private void getThumbNail (string strFileName, int iWidth, int iheight, string strContentType, bool blnGetFromFile, System.IO.Stream ImgStream) {system.drawing.image oimg;

if (blnGetFromFile) {oImg = System.Drawing.Image.FromFile (strFileName);} else {oImg = System.Drawing.Image.FromStream (ImgStream);} oImg = oImg.GetThumbnailImage (iWidth, iheight, null, IntPtr.Zero ); string strGuid = System.Guid.NewGuid () ToString () ToUpper ();.. string strFileExt = strFileName.Substring (strFileName.LastIndexOf ( ".")); Response.ContentType = strContentType; MemoryStream MemStream = new MemoryStream ( ); object-save (Memstream, GetImageType (strContentType); Memstream.writEto (Response.outputStream);

}

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

New Post(0)