0
在我的數據庫中,我有一個包含圖像列的表。在Crystal Report中查看存儲在SQL Server中的圖像
此欄的類型爲text
。
將圖像保存到可轉換爲文本的數據庫中時。
我的代碼是:
Image selectedImage = Image.FromFile(openFileDialog.FileName);
MemoryStream tmpStream = new MemoryStream();
selectedImage.Save(tmpStream, ImageFormat.Jpeg); // change to other format
tmpStream.Seek(0, SeekOrigin.Begin);
Byte[] BytesOfImage = tmpStream.ToArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < BytesOfImage.Length - 1; i++)
{
sb.Append(BytesOfImage[i] + ",");
}
sb.Append(BytesOfImage[BytesOfImage.Length - 1]);
sb.ToString(); // sb.ToString() ==> Save to sql server
然後將字符串轉換爲一張照片,我用下面的代碼:
String[] split = strImage.Split(',');
Byte[] bytes = new Byte[split.Length];
Byte b;
for (int i = 0; i < split.Length; i++)
{
Byte.TryParse(split[i], out b);
bytes[i] = b;
}
MemoryStream tmpStream = new MemoryStream();
tmpStream.Write(bytes, 0, bytes.Length);
tmpStream.Seek(0, SeekOrigin.Begin);
Image img = Image.FromStream(tmpStream);
現在,我想在我的報告將顯示圖像,但圖像路徑不存在,因爲圖像存儲在數據庫中!
如何查看圖像?
我怎麼能顯示圖像進入我的報告圖像變量?(我還沒有瀏覽圖像) – javadaskari
對不起,我從來沒有被工作用'CrystalReport'我只提出了我確定可以用來得到你想要的算法。 – Marek
@javadaskari如果這已經解決了您的問題,請將其標記爲答案,以便其他具有類似解決方案的人員將找到如何解決此問題。否則請解釋你的問題,所以我可以幫忙。 – Marek