.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理
问题比较简单,直接上代码.

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); }
        } 

 

posted on 2013-09-27 15:09  Tonyyang  阅读(614)  评论(1编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/