C # Base64 encoded text and image transfer

Source: Internet
Author: User

       /// <summary>          ///Base64 encoded text to image/// </summary>          /// <param name= "Txtfilepath" >file relative path (stored on server)</param>          /// <param name= "str" >Picture String</param>          Private voidBase64stringtoimage (stringTxtfilepath,stringstr) {            Try{String Inputstr=str; byte[] arr =convert.frombase64string (INPUTSTR); MemoryStream Ms=NewMemoryStream (arr); Bitmap BMP=NewBitmap (MS); Bmp. Save (System.Web.HttpContext.Current.Server.MapPath (Txtfilepath)+". jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //bmp.                  Save (Txtfilename + ". bmp", imageformat.bmp); //bmp.                  Save (Txtfilename + ". gif", imageformat.gif); //bmp.  Save (Txtfilename + ". png", imageformat.png); Ms.                Close (); //Imgphoto.imageurl = Txtfilepath + ". jpg"; //MessageBox.Show ("Conversion succeeded!")  ");             }            Catch(Exception ex) {}}
       protected stringImgtobase64string (stringImagePath) {            Try{Bitmap bmp=NewBitmap (System.Web.HttpContext.Current.Server.MapPath (ImagePath)); 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 (); returnconvert.tobase64string (arr); }            Catch(Exception ex) {return NULL; }        }

C # Base64 encoded text and image transfer

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.