. NET get picture binary byte data stream based on picture network address

Source: Internet
Author: User

        /// <summary>        ///get the bytes of a picture based on the HTML path/// </summary>         /// <param name= "Picsize" >image Size, Original: 1, big Picture: 2, figure: 3, Small picture: 4</param>         /// <param name= "Serverpath" >Image Server Address</param>        /// <returns></returns>         Public Static byte[] Getimagebytebyhtmlimgurl (stringImgsize,stringServerpath) {            byte[] bt =New byte[4096]; Try{Serverpath= Serverpath.replace ("_1.",string. Format ("_{0}.", imgsize)); Image obj=Image.fromstream (System.Net.WebRequest.Create (Serverpath). GetResponse ().                GetResponseStream ()); BT= ImageToByteArray (obj);//Use the ImageToByteArray () function to turn the image type to byte[] typeobj.                Dispose (); returnBT; }            Catch  //If you get an exception, use the picture in the resource to display            {                //Image obj = Image.fromstream (""); //byte[] bt = ImageToByteArray (obj); //obj.                Dispose (); //return BT;            }            returnBT; }        /// <summary>        ///gets the byte of a picture based on image/// </summary>        /// <param name= "image" ></param>        /// <returns></returns>        Private Static byte[] ImageToByteArray (image image) {System.IO.MemoryStream Mstream=NewSystem.IO.MemoryStream (); Image.            Save (Mstream, System.Drawing.Imaging.ImageFormat.Png); byte[] ret =Mstream.toarray ();            Mstream.close (); returnret; }

Codeby: Blog Park-Cao Yongxi, http://www.cnblogs.com/yonsy/p/3716483.html
Get picture image instance based on picture binary byte data stream

  /// <summary>        ///get an image instance based on the picture byte stream/// </summary>        /// <param name= "Imagebyte" ></param>        /// <returns></returns>         Public StaticImage Setbytetoimage (byte[] imagebyte)            {image Image; MemoryStream Imagememorystream=NewMemoryStream (Imagebyte,0, Imagebyte.            Length); Image=Image.fromstream (Imagememorystream); returnimage; }

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.