【发布时间】:2012-03-23 00:08:55
【问题描述】:
我正在努力在 silverlight 图像控件中显示图片。
该文件位于我的本地硬盘上。
是否可以将图像从硬盘加载到 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 无法访问我的本地驱动器有关吗?如果是这样,我将如何将图像动态加载到控件中?
非常感谢。
尼尔
更新:
通过直接从 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;
问候
尼尔
【问题讨论】:
标签: silverlight image controls