【发布时间】:2011-11-15 11:49:18
【问题描述】:
我花了相当多的时间试图从 SQLite 检索图像,但我失败了。如果有人可以帮助我解决我在这里做错的事情,那将不胜感激。下面是我用来检索存储在 SQLite 中的 BLOB 图像的代码。
SQLiteConnection con = new SQLiteConnection(Properties.Settings.Default.conString);
con.Open();
SQLiteCommand cmd = new SQLiteCommand("SELECT ImageFiles FROM basicconcepts WHERE id=1",con);
SQLiteDataReader reader=cmd.ExecuteReader();
byte[] imageBytes=null;
while (reader.Read())
{
imageBytes = (System.Byte[])reader["ImageFiles"];
}
MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
ms.Write(imageBytes, 0, imageBytes.Length);
pictureBox1.Image = Image.FromStream(ms, true);
这是我得到的错误的堆栈跟踪
System.ArgumentException was caught
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at WindowsFormsApplication1.frmMain.getPDF(String c_Name, Int32 pgNo) in C:\Users\Tanmay\Documents\My Projects\E-Excust\E-Excust\E-Excust\frmMain.cs:line 148
InnerException:
PS上面的代码在getPDF方法里面。
编辑
我找到了解决问题的方法。问题是,令人惊讶的是我正在使用的 sql 管理工具。我强烈建议不要使用 sqlite 管理员来检索 BLOB 图像。 我开始使用 SQLite Expert,一切都开始正常了。不敢相信我为此绞尽脑汁一整天 感谢大家的帮助,特别是那些没有在这里回答但在聊天中帮助我很多的人。非常感谢 usernane、yas4891、SomeGuy 和其他一些人
【问题讨论】:
-
pictureBox1是什么类型?图片保存时是什么格式的? -
图片为 Jpg 格式。 pictureBox1 因为我在我的表单上添加了一个图片框