我花了相當多的時間試圖從SQLite中檢索圖像,但是我失敗了。如果有人能幫我解決我在這裏做錯的事情,那將不勝感激。下面是我用來檢索存儲在SQLite中的BLOB圖像的代碼。將圖像從SQLite檢索到C的問題#
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,一切都開始正常工作。簡直不敢相信我一整天都在rack 012我的頭腦 感謝大家的幫助,特別是那些沒有在這裏回答,但在聊天中幫了我很多的人。非常感謝usernane,yas4891,SomeGuy和其他幾個人
是什麼類型'pictureBox1'?圖像保存時的格式是什麼? –
圖片爲Jpg格式。 pictureBox1因爲我已經在我的表格上添加了一個圖片框 – Tanmay