C # Image and BASE64 encoded reciprocal function

Source: Internet
Author: User

        /// <summary>        ///returns a encapsulated GDI + bitmap based on the Base64 string. /// </summary>        /// <param name= "base64string" >a Base64 string that can be converted to a bitmap. </param>        /// <returns>The Bitmap object. </returns>         PublicBitmap GetImageFromBase64 (stringbase64string) {            byte[] B =convert.frombase64string (base64string); MemoryStream Ms=NewMemoryStream (b); Bitmap Bitmap=NewBitmap (MS); returnbitmap; }        /// <summary>        ///converts a picture into a base64 string. /// </summary>        /// <param name= "ImageFile" >the picture file that needs to be converted. </param>        /// <returns>The base64 string. </returns>         Public stringGetbase64fromimage (stringimagefile) {            stringStrbaser64 =""; Try{Bitmap bmp=NewBitmap (ImageFile); using(MemoryStream ms =NewMemoryStream ()) {BMP.                    Save (MS, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arr =New byte[Ms.                    Length]; Ms. Position=0; Ms. Read (arr,0, (int) Ms.                    Length); Ms.                    Close (); Strbaser64=convert.tobase64string (arr); }            }            Catch(Exception) {Throw NewException ("Something wrong during convert!"); }            returnstrbaser64; }

C # Image and BASE64 encoded reciprocal function

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.