C # Image Processing (5): Lossless Image Storage

Source: Internet
Author: User

C # image loss occurs when the image is saved using the default method. The following method is provided:

1 /// <summary> 2 /// lossless save picture 3 /// </Summary> 4 /// <Param name = "imgresult"> picture </param> 5 /// <Param name = "path"> saved path </param> 6 // <Param name = "imagetype"> image type, image/JPEG, image/PNG, image/GIF, image/tiff, image/BMP </param> 7 // <returns> </returns> 8 Public bool saveimage (image imgresult, string path, string imagetype) 9 {10 encoderparameter P; 11 encoderparameters pS; 12 try13 {14 PS = new encoderparameters (1); 15 16 p = new encoderparameter (system. drawing. imaging. encoder. quality, 100l); 17 ps. param [0] = P; 18 19 imagecodecinfo II = getcodecinfo (imagetype); 20 imgresult. save (path, II, PS); 21 imgresult. dispose (); 22} 23 catch (exception ex) 24 {25 return false; 26} 27 return true; 28} 29 30 // <summary> 31 // obtain the image encoding type 32 // </Summary> 33 // <Param name = "mimetype"> </param> 34 // <returns> </returns> 35 public imagecodecinfo getcodecinfo (string mimetype) 36 {37 imagecodecinfo [] codecinfo = imagecodecinfo. getimageencoders (); 38 foreach (imagecodecinfo ICI in codecinfo) 39 {40 if (ici. mimetype = mimetype) return ICI; 41} 42 return NULL; 43}

 

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.