当前位置:   article > 正文

读取文件,C#中Image类赋值

c# image 赋值
 1 public override void OnApplyTemplate()
 2 {
 3     base.OnApplyTemplate();
 4 
 5     string imgtype = "*.BMP|*.JPG|*.GIF|*.PNG";
 6     string[] ImageType = imgtype.Split('|');
 7 
 8     for (int i = 0; i < ImageType.Length; i++)
 9     {
10         string[] dirs = Directory.GetFiles(@"e:\\Images", ImageType[i]);   //dirs为绝对路径
11         foreach (string dir in dirs)
12         {
13             Image img = new Image();
14             BitmapImage bitmap = new BitmapImage(new Uri(dir, UriKind.Absolute));   //以绝对路径形式设置Uri
15             img.Source = bitmap;
16             img.Height = 150;
17             img.Margin = new Thickness(1);
18             this.wp2.Children.Add(img);
19         }
20     }
21 }

 

转载于:https://www.cnblogs.com/qiups/p/8682516.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/1001705
推荐阅读
相关标签
  

闽ICP备14008679号