XAF 如何将数据库中Byte array图片显示出来

问题比较简单,直接上代码.

private Image _Cover; [Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValueConverter))] public Image Cover { get { if (_Cover == null && _Photo != null && _Photo.Length > 0) { using (MemoryStream stream = new System.IO.MemoryStream(_Photo)) { System.Drawing.Image image = System.Drawing.Image.FromStream(stream); _Cover = image; return _Cover; } } return _Cover; } set { SetPropertyValue("Cover", ref _Cover, value); } } private Byte[] _Photo; //[Delayed] public Byte[] Photo { get { return _Photo; } set { //byte[] imagedata = null; //if (Cover != null) //{ // MemoryStream ms = new MemoryStream(); // Image im = new Bitmap(Cover); // im.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // imagedata = ms.GetBuffer(); // _Photo = imagedata; //} SetPropertyValue("Photo", ref _Photo, value); } }
复制代码

 XAF自带,varbinary(Max)类型图片操作方法:

复制代码
   Image fPhoto;
        [ValueConverter(typeof(ImageValueConverter)), Delayed]
        public Image Photo
        {
            get { return fPhoto; }
            set { SetPropertyValue("Photo", ref fPhoto, value); }
        } 

你可能感兴趣的:(XAF 如何将数据库中Byte array图片显示出来)