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