Get the image resolution:
Public static system. io. stream filedatastream = NULL; filedatastream = fileupload1.postedfile. inputstream; system. drawing. image image = system. drawing. image. fromstream (filedatastream); // instantiate the image class float W = image from the uploaded file stream. width; // obtain the horizontal resolution of the uploaded file (in pixels/inches ). Float H = image. height; // obtain the vertical resolution of the uploaded file (in pixels/inches ).
Obtain the image size:
Public static int filelength = 0;
Filelength = fileupload1.postedfile. contentlength; // obtains the content size of the fileupload upload control, which exists in bytes.
Image compression:
# Region compressed image /// <summary> /// compressed image /// </Summary> /// <Param name = "filepath"> path of the image to be compressed </param> // <Param name = "filepath_ystp"> path of the compressed image </param> Public void ystp (Stream filedatastream, string filepath_ystp) {// Bitmap bitmap BMP = NULL; // imagecoderinfo imagecodecinfo ICI = NULL; // encoder ICD = NULL; // encoderparameter EPT = NULL; // encoderparameters epts = NULL; try {BMP = new Bitmap (filedatastream); ICI = This. getimagecoderinfo ("image/JPEG"); MCM = encoder. quality; epts = new encoderparameters (1); EPT = new encoderparameter (MCM, 10l); epts. param [0] = EPT; BMP. save (filepath_ystp, ici, epts);} catch (exception ex) {Throw new exception (ex. message);} finally {BMP. dispose (); EPT. dispose (); epts. dispose ();}} /// <summary> /// obtain the image encoding type information /// </Summary> /// <Param name = "codertype"> encoding type </param> // /<returns> imagecodecinfo </returns> private imagecodecinfo getimagecoderinfo (string codertype) {imagecodecinfo [] ICIS = imagecodecinfo. getimageencoders (); imagecodecinfo retici = NULL; foreach (imagecodecinfo ICI in ICIS) {If (ici. mimetype. equals (codertype) retici = ICI;} return retici ;}# endregion compressed image
Get the file extension
Private Static bool isallowedextension (fileupload upfile) {string stroldfilepath = ""; string strextension = ""; string [] arrextension = {". jpg "}; If (upfile. postedfile. filename! = String. empty) {stroldfilepath = upfile. postedfile. filename; // obtain the complete file path strextension = stroldfilepath. substring (stroldfilepath. lastindexof (". ")). tolower (); // get the file extension, such :. JPG for (INT I = 0; I <arrextension. length; I ++) {If (strextension. equals (arrextension [I]) {return true ;}}return false ;}