zoukankan      html  css  js  c++  java
  • How to Load Images from a Stream

    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.

    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
    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    java 枚举类小结 Enum
    hibernate查询
    java装饰者模式理解
    内部类学习
    java使用json将HashMap转化成javabean小例子
    HashMap存储数据赋值javabean简单示例
    java数组转化成集合
    java正则匹配并提取字串
    Windows cmd命令反斜杠问题
    自动化构建工具
  • 原文地址:https://www.cnblogs.com/starcrm/p/1574197.html
Copyright © 2011-2022 走看看