ASP obtains the image size and pixels, resolution, and compression.

Source: Internet
Author: User

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 ;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.