/// <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; }