Ejemplo n.º 1
0
        /// <summary>
        ///  共有の<c>DataPackageView</c>からこのクラスのインスタンスを作成する.
        /// </summary>
        /// <param name="package">共有の<c>DataPackageView</c></param>
        /// <returns>このクラスのインスタンス</returns>
        public static async Task <SharedBitmapItem> CreateFromDataPackage(DataPackageView package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            if (!package.Contains(StandardDataFormats.Bitmap))
            {
                return(null);
            }

            var bmpStream = await package.GetBitmapAsync();

            using (var bmpStreamWithContentType = await bmpStream.OpenReadAsync())
            {
                var bmpImage = new BitmapImage();
                bmpImage.SetSource(bmpStreamWithContentType);

                var item = new SharedBitmapItem(bmpImage);
                await item.KeepSharedBitmapInfoAsync(bmpStreamWithContentType);

                return(item);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  共有データに含まれる画像とファイルを登録候補として追加する.
        /// </summary>
        /// <param name="shareOperation"></param>
        private async Task AddSharedItemsAsync(ShareOperation shareOperation)
        {
            var bmpItem = await SharedBitmapItem.CreateFromDataPackage(shareOperation.Data);

            if (bmpItem == null)
            {
                return;
            }

            this.mainCanvas.Item      = new CanvasItem();
            this.mainCanvas.IsEditing = true;

            if (this.sharedItemCache == null)
            {
                this.sharedItemCache = new CameraCache("SharedItemCache");
                await this.sharedItemCache.ClearAsync();
            }

            await bmpItem.PrepareFileAsync();

            await this.sharedItemCache.MoveAndAddAsync(bmpItem.File);

            await this.mainCanvas.SetImageAsync(bmpItem.File, true);

            this.sharedBitmapItem = bmpItem;
        }