C # returns the byte stream of the image []

Source: Internet
Author: User

C # returns the byte stream of the image []

# Region returns the byte stream of the image byte [] ///// Byte [] ///////////
 Public static 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. open) {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 image conversion to word throttling ////// Convert the image into word throttling //////Image object to be converted ///
 
  
Byte stream returned after conversion
 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


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.