Find a picture relative to a picture and convert it into a binary format
/// <summary> ///Picture Conversion/// </summary> /// <param name= "strpath" ></param> /// <returns></returns> Private byte[] Redyte (stringstrpath) { byte[] bytes =NULL; Try{FileStream Fsmyfile=NULL; if(Directory.Exists (Server.MapPath (strpath))) {//read files in binary modeFsmyfile =NewFileStream (Server.MapPath (strpath), FileMode.OpenOrCreate, FileAccess.ReadWrite); } Else{fsmyfile=NewFileStream (Server.MapPath (Savedir +"/default.jpg"), FileMode.OpenOrCreate, FileAccess.ReadWrite); } //Create a binary data stream reader, and open file associationsBinaryReader Brmyfile =NewBinaryReader (Fsmyfile); //Reposition the file pointer to the beginning of the fileBrMyfile.BaseStream.Seek (0, Seekorigin.begin); Bytes=brmyfile.readbytes (Convert.ToInt32 (fsMyfile.Length.ToString ())); //close each of these new objectsBrmyfile.close (); } Catch { //read files in binary modeFileStream Fsmyfile =NewFileStream (Server.MapPath (Savedir +"/default.jpg"), FileMode.OpenOrCreate, FileAccess.ReadWrite); //Create a binary data stream reader, and open file associationsBinaryReader Brmyfile =NewBinaryReader (Fsmyfile); //Reposition the file pointer to the beginning of the fileBrMyfile.BaseStream.Seek (0, Seekorigin.begin); Bytes=brmyfile.readbytes (Convert.ToInt32 (fsMyfile.Length.ToString ())); //close each of these new objectsBrmyfile.close (); } returnbytes; }View Code
Save pictures to local based on network path
/// <summary> ///save URL picture to local/// </summary> /// <param name= "url" ></param> /// <param name= "Savepath" ></param> Private stringSaveurlimage (stringURL) { stringSavepath =""; Try{HttpWebRequest WebRequest=(HttpWebRequest) webrequest.create (URL); HttpWebResponse WebResponse=(HttpWebResponse) WebRequest. GetResponse (); if(WebResponse. StatusCode = =Httpstatuscode.ok) {System.Drawing.Image Image=System.Drawing.Image.FromStream (WebResponse. GetResponseStream ()); Savepath= Savedir +"/"+ DateTime.Now.ToString ("yyyymmddhhmmssfffff") +". jpg"; Image. Save (Server.MapPath (Savepath)); //Save in local folderImage. Dispose ();//Freeing Resources } } Catch { } returnSavepath; }View Code
Save binary format picture to local
New System.IO.MemoryStream (imgdata); = System.Drawing.Image.FromStream (ms); Img. Save (Savepath);
View Code
Check if the file exists
Directory.Exists (Severdir)
View Code
Reference: http://developer.51cto.com/art/200908/143612.htm
http://www.oschina.net/code/snippet_222150_15091
About picture Conversions