Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi ,
this is parashuram
i would like to know that i want to convert jpg format into binary form to store in sql server table as a column..
and also retrieve back from binary to jpg format.in my windows application.

so plz do the needful to my requirement.
Posted
Comments
Kornfeld Eliyahu Peter 14-Jan-15 7:13am    
JPEG IS a binary format...

 
Share this answer
 
I assume you mean to convert to a byte array which can be stored in and retrieved from an image item in SQL Server?

C#
public static byte[] OpenImageToByteArray(Image image, ImageFormat format)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, format);
                return ms.ToArray();
            }
        }

 //Now write the result to SQL Server...


And the reverse

C#
//Get the value from SQL Server...

        public static Image OpenImageFromByteArray(byte[] image)
        {
            using (MemoryStream stream = new MemoryStream(image, true))
            {
                return Image.FromStream(value);
            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900