我正在努力在Silverlight圖像控件中顯示圖片。Silverlight - 從本地硬盤上的文件顯示圖像控制中的PNG
該文件位於本地硬盤上。
是否可以將硬盤中的圖像加載到silverlight圖像控件中?
到目前爲止,我搜索的所有東西似乎都不涉及從硬盤加載。
我需要先將它保存爲資源嗎?
我目前在做這樣的事情:
Image pic = new Image();
Uri uri = new Uri(@"C:\Briefcase\PDF.bmp", UriKind.Relative);
pic.Source = new System.Windows.Media.Imaging.BitmapImage(uri);
canvas.Children.Add(pic);
pic.SetValue(Canvas.LeftProperty, Convert.ToDouble(100));
pic.SetValue(Canvas.TopProperty, Convert.ToDouble(100));
pic.Height = 70;
pic.Width = 600;
是我的Uri是否正確?因爲我也嘗試過:
Uri uri = new Uri("C:/Briefcase/PDF.bmp", UriKind.Relative);
這是否也許與silverlight無法訪問我的本地驅動器有關?如果是的話我會如何動態地將圖像加載到控件中?
非常感謝。
奧尼爾
UPDATE:
解決我的問題,直接從MemoryStream的圖像加載到圖像控制
byte[] logo = e.Result;
logoStream = new System.IO.MemoryStream(logo);
System.Windows.Media.Imaging.BitmapImage b = new System.Windows.Media.Imaging.BitmapImage();
b.SetSource(logoStream);
ownerLogo.Source = b;
問候
奧尼爾
我想要做的是從sql中讀取圖像並將其顯示爲標誌。我可以從數據庫中檢索圖像沒有問題,那麼顯示它的最簡單方法是什麼?我可以直接從MemoryStream中做到嗎?或者,如果沒有,我可以以編程方式將其添加爲資源? – Neill 2012-03-05 14:41:08
查看更新的答案 - 謝謝你指着我在正確的方向 – Neill 2012-03-05 14:48:41