简体   繁体   中英

Compress picture and photos to store in SQL Server database

I want to save many pictures into a SQL Server database file. How can I compress pictures to store in database? What technologies can I use?

Please help me

After Edit: How Can I Compress And Resize Pictures to Store in Sql Server DataBase?

Pictures don't compress much if they already in jpg and most other formats. You could try compressing them further before sending to SQL Server but it probably isn't worth the effort, unless you have BMPs.

I suggest you look at FILESTREAM to store them in SQL Server (assuming SQL Server 2008) which is more efficient for this kind of data.

You could save them in JPEG and include the file. For doing it, you can use Image.Save method . And if you want to set the quality you can use Encoder.Compression .

You should also make sure that the resolution of the images is not too much.

You can store pictures in sql database by convert images to byte array.You can do it with below code :

    byte[] ReadFile(string sPath)
    {
        byte[] data = null;
        FileInfo fInfo = new FileInfo(sPath);
        long numBytes = fInfo.Length;
        FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fStream);
        data = br.ReadBytes((int)numBytes);
        return data;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM