C # picture to binary/string binary/string inversion into picture

Source: Internet
Author: User

    protected void Button1_Click (object sender, EventArgs e) {//Picture goto binary byte[] Imagebyte = Getpicturedata        (Server.MapPath ("./uploadfile/111.png"));        Binary converted to String picstr = Convert.tobase64string (imagebyte);        Output String Response.Write (PICSTR);        string-to-binary byte[] imagebytes = convert.frombase64string (PICSTR);        Read in MemoryStream object MemoryStream MemoryStream = new MemoryStream (imagebytes, 0, imagebytes.length);        Memorystream.write (imagebytes, 0, imagebytes.length);        Binary into picture save System.Drawing.Image image = System.Drawing.Image.FromStream (MemoryStream); Image.    Save (Server.MapPath ("./uploadfile/222.png"));    }///<summary>///binary flow picture///</summary>//<param name= "Streambyte" > Binary stream </param> <returns> Pictures </returns> public System.Drawing.Image returnphoto (byte[] streambyte) {SYSTEM.I O.memorystream ms = new System.IO.MemoryStream (streamByte);        System.Drawing.Image img = System.Drawing.Image.FromStream (ms);    return img;    }///<summary>//image to binary///</summary>//<param name= "ImagePath" > Image address </param> <returns> binary </returns> public byte[] Getpicturedata (string imagepath) {/////based on the path of the picture file is opened using a file stream. and save as byte[] FileStream fs = new FileStream (ImagePath, FileMode.Open);//Can be other overloaded method byte[] Bydata = new Byte[f        S.length]; Fs.        Read (bydata, 0, bydata.length); Fs.        Close ();    return bydata; }///<summary>//Picture to binary///</summary>//<param name= "Imgphoto" > Picture object </param>/ <returns> binary </returns> public byte[] Photoimageinsert (System.Drawing.Image imgphoto) {//Will Imag        E is converted into stream data and saved as byte[] MemoryStream mstream = new MemoryStream ();        Imgphoto.save (Mstream, SYSTEM.DRAWING.IMAGING.IMAGEFORMAT.BMP); byte[] Bydata = new Byte[mstream.      Length];  Mstream.        Position = 0; Mstream.        Read (bydata, 0, bydata.length); Mstream.        Close ();    return bydata; }

C # picture to binary/string binary/string inversion into picture

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.