About picture Conversions

Source: Internet
Author: User

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

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.