Exemple #1
0
        protected async Task SaveThumbail(Func <byte[], Thumbnail> funcGetThumbnail, byte[] data)
        {
            using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
            {
                // Encode pixels into stream
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ras);

                encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, (uint)ThumbnailSize.Width, (uint)ThumbnailSize.Height, 96, 96, data);
                await encoder.FlushAsync();

                byte[] pngPixel = new byte[ras.Size];
                ras.AsStreamForRead().Read(pngPixel, 0, (int)ras.Size);

                //DB 등록
                ThumbnailDAO.InsertThumbnail(funcGetThumbnail.Invoke(pngPixel));
            }
        }
Exemple #2
0
        //원드라이브로 부터 썸네일로 이미지를 다운로드 받아,
        //NetworItemInfo에 이미지를 로딩 시킨후 DB에 캐쉬로 저장한다.
        private async Task StoreImageFromWeb(NetworkItemInfo networkItem, Microsoft.OneDrive.Sdk.Thumbnail itemThumb)
        {
            if (itemThumb != null)
            {
                try
                {
                    var webReq = System.Net.WebRequest.Create(itemThumb.Url);
                    await GalaSoft.MvvmLight.Threading.DispatcherHelper.RunAsync(async() =>
                    {
                        using (var webRes = await webReq.GetResponseAsync())
                        {
                            using (var imageStream = webRes.GetResponseStream())
                            {
                                WriteableBitmap wb           = await BitmapFactory.FromStream(imageStream);
                                networkItem.ImageItemsSource = wb;

                                using (InMemoryRandomAccessStream newStream = new InMemoryRandomAccessStream())
                                {
                                    await wb.ToStream(newStream, BitmapEncoder.PngEncoderId);
                                    byte[] pngData = new byte[newStream.Size];
                                    await newStream.ReadAsync(pngData.AsBuffer(), (uint)pngData.Length, InputStreamOptions.None);

                                    //DB 등록
                                    ThumbnailDAO.InsertThumbnail(new Models.Thumbnail
                                    {
                                        Name            = networkItem.Name,
                                        ParentPath      = networkItem.ParentFolderPath,
                                        Size            = (ulong)networkItem.Size,
                                        RunningTime     = networkItem.Duration,
                                        CreatedDateTime = networkItem.Modified,
                                        ThumbnailData   = pngData
                                    });
                                }
                            }
                        }
                    });
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }