public override void LoadedFromData(ILazyLoadingItem loadedData) { if (IsCached) { return; } IsCached = true; if (!string.IsNullOrEmpty(this.ThumbnailKey)) { using (var proxy = new MogamiApiServiceClient()) { proxy.Login(); var loadthumbparam = new REQUEST_LOADTHUMBNAIL { ThumbnailKey = ThumbnailKey }; var rsp = proxy.LoadThumbnail(loadthumbparam); using (Stream stream = new MemoryStream(rsp.ThumbnailBytes)) { // ロックしないように指定したstreamを使用する。 BitmapDecoder decoder = BitmapDecoder.Create( stream, BitmapCreateOptions.None, // この辺のオプションは適宜 BitmapCacheOption.Default // これも ); BitmapSource bmp = new WriteableBitmap(decoder.Frames[0]); bmp.Freeze(); this.Thumbnail = bmp; } } } }
public RESPONSE_LOADTHUMBNAIL LoadThumbnail(REQUEST_LOADTHUMBNAIL reqparam) { var rsp = new RESPONSE_LOADTHUMBNAIL(); using (var tdbc = new ThumbDbContext()) { var repo = new ThumbnailRepository(tdbc); var thumb = repo.FindFromKey(reqparam.ThumbnailKey).FirstOrDefault(); if (thumb != null) { LOG.InfoFormat("サムネイルの送信={0}", thumb.BitmapBytes.Count()); rsp.ThumbnailBytes = thumb.BitmapBytes; } } rsp.Success = true; return(rsp); }