How to Load Images from a Stream
2009-09-25 17:54
507 查看
Due to obvious security reasons Silverlight cannot directly load files from a client box. However, in response to an event like a button Silverlight can load files through the OpenFileDialog where the client gets to choose what file to load.
The following sample shows you how to load a PNG file once a use clicks on a button. In the code below, “MyImage” is an Image control that I declared in my XAML. BitmapImage can be found in System.Windows.Media.Imaging.
The following sample shows you how to load a PNG file once a use clicks on a button. In the code below, “MyImage” is an Image control that I declared in my XAML. BitmapImage can be found in System.Windows.Media.Imaging.
private void Button_Click_Load_Image(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PNG Files (*.png;*.png)|*.png;*.png | All Files (*.*)|*.*";
ofd.FilterIndex = 1;
if (true == ofd.ShowDialog())
{
System.IO.Stream stream = ofd.File.OpenRead();
BitmapImage bi = new BitmapImage();
bi.SetSource(stream);
MyImage.Source = bi;
stream.Close();
}
}Thank you
相关文章推荐
- How to Load Images from a Stream
- How to use OpenCV to capture and display images from a camera
- How to select Multiple images from UIImagePickerController [duplicate]
- How to use virtual path providers to dynamically load and compile content from virtual paths in
- How To Load CLOB Data from a File into a CLOB column using PL/SQL
- 如何从EXCEL文件加载Hierarchy到BW (How to Load Hierarchy From Flat File)
- how-to-load-resource-from-jar-file-packaged-in-a-war-file
- How to stop ASP.NET from loading all assemblies from bin on first load
- [WebView] How to display local images from a remotely loaded URL web page?
- How to capture video frames from the camera as images using AV Foundation on iOS
- Delphi XE2 之 FireMonkey 入门(33) - 控件基础: TFmxObject: SaveToStream、LoadFromStream、SaveToBinStream、LoadFromBinStream
- How to capture video frames from the camera as images using AV Foundation
- How to Load Dialog From a Resource DLL?
- Delphi XE2 之 FireMonkey 入门(33) - 控件基础: TFmxObject: SaveToStream、LoadFromStream、SaveToBinStream、LoadFromBinStream
- ios学习--How to capture video frames from the camera as images using AV Foundation
- How to Dynamically Load a Control from a DLL
- 学习 TTreeView [6] - SaveToFile、LoadFromStream、SaveToStream、LoadFromFile
- How to load a referenced dll from specified location not GAC
- How to capture video frames from the camera as images using AV Foundation
- How to read images from drawable folder, not by R.drawable.[imageid]