Convert a picture file into a binary array in C #-for database storage

Source: Internet
Author: User

In project development, using SQL Server to store data, the data type image can save the picture. However, it is necessary to convert the picture into a binary array before storing it in the form of a value assignment.

Convert a picture file to a binary array
/// <summary>   ///Convert a picture file to a binary array/// </summary>   /// <param name= "Picpath" >Picture Path</param>   /// <returns>Binary Arrays</returns>   Private byte[] Getbinarydata (String picpath)//Convert a picture file to byte[]{       //read-only mode to open a picture to a streamFileStream FS=NewFileStream (Picpath, FileMode.Open, FileAccess.Read); //Initializes a binary array of exactly the same length imagebytesbyte[] Imagebytes=New byte[FS.       Length]; //reads the full text from the stream and writes to the binary array imagebytesFS. Read (Imagebytes,0, Convert.ToInt32 (fs.       Length)); //Remember to release the streamFS.       Flush (); Fs.       Close (); //back to Imagebytes    returnimagebytes; }  

Convert a picture file into a binary array in C #-for database storage

Related Article

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.