Development journey (8): mutual conversion between images and byte []

Source: Internet
Author: User
1 // The image's "read" Operation 2 // ① parameter is the image path: returned byte [] type: 3 // The parameter is the image Path 4 Public byte [] getpicturedata (string ImagePath) {5 filestream FS = new filestream (ImagePath, filemode. open); 6 byte [] bytedata = new byte [FS. length]; 7 FS. read (bytedata, 0, bytedata. length); 8 FS. close (); 9 return bytedata (); 10} 11 // The parameter type is an image object, and the byte [] Type 12 // converts the image to the stream data, save as byte [] & nbsp; 13 public byte [] photoimageinsert (system. drawing. image imgphoto) 14 {15 memorystream mstream = new memorystream (); 16 imgphoto. save (mstream, system. drawing. imaging. imageformat. BMP); 17 byte [] bydata = new byte [mstream. length]; 18 mstream. position = 0; 19 mstream. read (bydata, 0, bydata. length); mstream. close (); 20 return bydata; 21} 22 // The "write" operation for the image 23 // ① parameter is of the byte [] type, and the return value is the image object 24 public system. drawing. image returnphoto (byte [] streambyte) 25 {26 system. io. memorystream MS = new system. io. memorystream (streambyte); 27 system. drawing. image IMG = system. drawing. image. fromstream (MS); 28 return IMG; 29} 30 // The parameter is of the byte [] type and has no return value (Asp. net output image) 31 public void writephoto (byte [] streambyte) 32 {33 // response. the default value of contenttype is "text/html" 34 response. contenttype = "image/GIF"; 35 // The image output types include: image/GIF image/JPEG 36 response. binarywrite (streambyte); 37}

 

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.