C # returns the byte stream of a picture byte[]

Source: Internet
Author: User
#region The byte stream that returns the picture byte[]///<summary>///byte[]///</summary>///<para M name= "ImagePath" >///<param name= "webClient" >//<returns></returns> public s            Tatic byte[] Getimagebyte (string imagePath, WebClient WebClient) {byte[] imgbyte = null;                try {//messagebox.show ("getimagebyte");                Stopwatch Stopwatch = new Stopwatch (); Stopwatch.                Start ();                 DateTime DateStart = DateTime.Now; if (Pubfunc.urldiscern (ImagePath)) {Bitmap BT = new Bitmap (Webclient.openread (ImagePath                    ));                Imgbyte = Pubfunc.imgtobyte (BT); } else {using (FileStream files = new FileStream (ImagePath, Filemode.ope N) {imgbyte = new byte[files.              Length];          Files.                        Read (imgbyte, 0, imgbyte.length); Files.                    Close (); }}//stopwatch.                Stop (); MessageBox.Show ((Datetime.now-datestart).             Totalmilliseconds.tostring ()); } catch (Exception ee) {MessageBox.Show (EE.            ToString ());        } return imgbyte; } #endregion
#region picture converted to byte stream///<summary>///      picture converted to byte stream///      </summary>      ///<param name= "img" > The image object to convert      ////<returns> The byte stream returned after conversion </returns> public      static byte[] imgtobyte (Image img)      {          Try          {              using (MemoryStream ms = new MemoryStream ())              {                  byte[] imagedata = null;                  Img. Save (MS, System.Drawing.Imaging.ImageFormat.Jpeg);                  ImageData = Ms. GetBuffer ();                  return imagedata;              }          }          catch (Exception ee)          {              MessageBox.Show (EE. ToString ());              return null;          }      }      #endregion

The above is the C # return picture of the byte stream byte[] content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.