c# – SqLite中存储的图像占用的空间增加了2倍

我想将jpg图像存储在SqLite数据库中,我现在正在使用此代码:

public byte[] ImageToByte(Image image, System.Drawing.Imaging.ImageFormat format)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, format);
                byte[] imageBytes = ms.ToArray();
                return imageBytes;
            }
        }
void btn_click()...
{
                photo = new Bitmap("invoker.jpg");
                pic = ImageToByte(photo, System.Drawing.Imaging.ImageFormat.Jpeg);
                SaveImage(pic);
}

更新:

void SaveImage(byte[] imagen)
        {
            string conStringDatosUsuarios = @" Data Source = \bang.sqlite3 ;Version=3";
            SQLiteConnection con = new SQLiteConnection(conStringDatosUsuarios);
            SQLiteCommand cmd = con.CreateCommand();
            cmd.CommandText = String.Format("INSERT INTO tbl_pictures (record_id, pic) VALUES ('1', @0);");
            SQLiteParameter param = new SQLiteParameter("@0", System.Data.DbType.Binary);
            param.Value = imagen;
            cmd.Parameters.Add(param);
            con.Open();

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception exc1)
            {
                MessageBox.Show(exc1.Message);
            }
            con.Close();
        }

解决方法:

我认为从jpg创建一个Bitmap是导致大小增加的步骤.实际上,我很惊讶这只是2倍的尺寸增加!

根据维基百科(http://en.wikipedia.org/wiki/JPEG#Sample_photographs),压缩比可以从2.6倍到46倍以上.

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能