问题比较简单,直接上代码. private Image _Cover;
[Size(SizeAttribute.Unlimited), ValueConverter(typeof(ImageValueConverter))]
public Image Cover
{
get
{
if (_Cover == null && _Photo != null && _Photo.Length > )
{
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); }
}