从byte数组byte[]转换为bitmapsource以及反射实现属性批量赋值

从byte数组byte[]转换为bitmapsource

(BitmapSource)new ImageSourceConverter().ConvertFrom(b)

名字有规律的属性代码用反射优美实现

  for(int i=0;i<imageList.Tables[0].Rows.Count;i++)
                {
                      if(imageList.Tables[0].Rows[i]!=null)
                      {
                            System.Data.DataRow tab = imageList.Tables[0].Rows[i];
                            BitmapSource source=(BitmapSource)new ImageSourceConverter().ConvertFrom((byte[])tab.ItemArray[0]);
                            System.Reflection.PropertyInfo propertyInfo=this.GetType().GetProperty("Image" + (i + 1));
                            propertyInfo.SetValue(this, source, null);
                      }                  
                   
                }           

 

posted @ 2018-10-11 18:24  出门必戴双肩包  阅读(940)  评论(0编辑  收藏  举报