我拼命嘗試將圖像保存到SQL數據庫,然後將其加載到我的WP上。所有在線指南都表示將圖像轉換爲字節數組,存儲它,然後將其重新加載到圖像中。如何將圖像存儲在WP7上的SQL數據庫中
到目前爲止,我已經能夠將圖像保存到使用一個字節數組:
public static byte[] ConvertToBytes(Stream photoStream)
{
byte[] a = new Byte[photoStream.Length];
for (int i = 0; i < photoStream.Length; i++)
{
a[i] = (Byte)photoStream.ReadByte();
}
return (a);
}
這生成的字節數組的大小與我保存圖像相似。
建議的方式來加載圖像是:
1 public static BitmapImage ConvertToImage(Byte[] inputBytes)
2 {
3 MemoryStream stream = new MemoryStream(inputBytes);
4 BitmapImage image = new BitmapImage();
5 image.SetSource(stream);
6 return (image);
7 }
這是行不通的。
我得到這個錯誤(第5行): 「未指定的錯誤」
沒有任何人有任何想法如何解決這個問題還是可以提出一個替代方法/代碼?
我知道網上有信息 - 我可以向你保證,我已經搜索了很長時間,很難找到一種工作方法,並且無能爲力。
任何幫助將不勝感激!
請說明如何從數據庫中獲取inputbytes。 –
試試這個鏈接http://www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/我相信它可以幫助 – MethodMan
爲了測試的目的,米甚至沒有使用數據庫。我將圖像轉換爲字節,然後將這些字節發送到ConvertToImage。我正在查看你的鏈接DJ KRAZE – Cameron