Пример #1
0
        private async void AddAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var         camera = new CameraCaptureUI();
            StorageFile file   = await camera.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                image.Source     = bitmapImage;
                this.DataContext = file;
                // Add picked file to MostRecentlyUsedList.
            }
            else
            {
                MessageDialog msgbox = new MessageDialog("Файл не выбран", "Внимание");
                await msgbox.ShowAsync();
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the given <paramref name="pic"/> with another picture.
        /// </summary>
        /// <param name="pic"><see cref="Windows.UI.Xaml.Controls.PersonPicture"/> to be changed</param>
        /// <returns>bool? result of the job done.</returns>
        public static async System.Threading.Tasks.Task <bool?> SetPictureAsync(Windows.UI.Xaml.Controls.PersonPicture pic)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            var file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                image.SetSource(stream);
                pic.ProfilePicture = image;
                return(true); //picture changed successfully
            }
            else
            {
                return(null); //the file is null
            }
        }
Пример #3
0
        private async void OpenAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".mp4");
            var file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.

            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                image.Source     = bitmapImage;
                this.DataContext = file;
                // Add picked file to MostRecentlyUsedList.
            }
            else
            {
                MessageDialog msgbox = new MessageDialog("Файл не выбран", "Внимание");
                await msgbox.ShowAsync();
            }
        }
Пример #4
0
        private async void GetPhoto_Click(object sender, RoutedEventArgs e)
        {
            //File picker APIs don't work if the app is in a snapped state.
            //Try to unsnap the app first.  only launch the picker if it unsnapped

            if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped ||
                Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true)
            {
                Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
                openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
                openPicker.FileTypeFilter.Clear();
                openPicker.FileTypeFilter.Add(".bmp");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".png");

                Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

                if (file != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    displayImage.Source = bitmapImage;
                    this.DataContext    = file;

                    mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
                }
            }
        }
        public async Task GetProjectLogo()
        {
            // Arrange
            ProjectsService svc = new ProjectsService(await GetAuthenticationService());
            // Act
            var projects = await svc.GetProjects();

            if (projects?.Count() > 0)
            {
                var first = projects.First();
                int width = 100, height = 100;
                var stream = await svc.GetProjectLogo(first.Id, width, height);

                // Create a .NET memory stream.
                var memStream = new MemoryStream();
                // Convert the stream to the memory stream, because a memory stream supports seeking.
                await stream.CopyToAsync(memStream);

                // Set the start position.
                memStream.Position = 0;
                // UI Thread needed
                await ExecuteOnUIThreadAsync(() =>
                {
                    // Create a new bitmap image.
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    // Set the bitmap source to the stream, which is converted to a IRandomAccessStream.
                    bitmap.SetSource(memStream.AsRandomAccessStream());
                });
            }
            // Assert
            // TODO
        }
        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker();
            filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".jpeg");
            filePicker.FileTypeFilter.Add(".png");
            filePicker.FileTypeFilter.Add(".bmp");
            filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    Image.Source = bitmapImage;
                    ImageName    = file.Name;
                    ImagePath    = file.Path;
                    Windows.Storage.StorageFolder targetFolder = await StorageFolder.GetFolderFromPathAsync(Models.TodoItem.ImagePath);

                    await file.CopyAsync(targetFolder, ImageName, NameCollisionOption.ReplaceExisting);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            if (pageState != null && pageState.ContainsKey("mruToken"))
            {
                object value = null;
                if (pageState.TryGetValue("mruToken", out value))
                {
                    if (value != null)
                    {
                        mruToken = value.ToString();
                        //reopen the file with the stored token.
                        Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken);

                        if (file != null)
                        {
                            Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                            Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                            bitmapImage.SetSource(fileStream);
                            displayImage.Source = bitmapImage;
                            this.DataContext    = file;
                        }
                    }
                }
            }
        }
Пример #8
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                displayImage.Source = bitmapImage;
                this.DataContext    = file;
            }
        }
Пример #9
0
        /// <summary>
        /// 将获取到的流转成bitmap
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public Windows.UI.Xaml.Media.Imaging.BitmapImage ConverToBitmapImage(IRandomAccessStream stream)
        {
            var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            bitmap.SetSource(stream);
            return(bitmap);
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            if (pageState != null && pageState.ContainsKey("mruToken"))
            {
                object value = null;
                if (pageState.TryGetValue("mruToken", out value))
                {
                    if (value != null)
                    {
                        mruToken = value.ToString();

                        // Open the file via the token that you stored when adding this file into the MRU list.
                        Windows.Storage.StorageFile file =
                            await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken);

                        if (file != null)
                        {
                            // Open a stream for the selected file.
                            Windows.Storage.Streams.IRandomAccessStream fileStream =
                                await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                            // Set the image source to a bitmap.
                            Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                                new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                            bitmapImage.SetSource(fileStream);
                            displayImage.Source = bitmapImage;

                            // Set the data context for the page.
                            this.DataContext = file;
                        }
                    }
                }
            }
        }
Пример #11
0
        private async void image_Click(object sender, RoutedEventArgs e)
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".png");

            var file = await openPicker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmap.SetSource(stream);

                Image1.Source = bitmap;
            }
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            if (pageState != null && pageState.ContainsKey("mruToken"))
            {
                object value = null;
                if (pageState.TryGetValue("mruToken", out value))
                {
                    if (value != null)
                    {
                        mruToken = value.ToString();

                        // Open the file via the token that you stored when adding this file into the MRU list.
                        Windows.Storage.StorageFile file =
                            await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken);

                        if (file != null)
                        {
                            // Open a stream for the selected file.
                            Windows.Storage.Streams.IRandomAccessStream fileStream =
                                await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                            // Set the image source to a bitmap.
                            Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                                new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                            bitmapImage.SetSource(fileStream);
                            displayImage.Source = bitmapImage;

                            // Set the data context for the page.
                            this.DataContext = file;
                        }
                    }
                }
            }
        }
Пример #13
0
        private async System.Threading.Tasks.Task <bool> SetDefaultPicture()
        {
            var uri = new System.Uri("ms-appx:///Assets/Photo.png");

            Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);

            if (file != null)
            {
                using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    if (fileStream != null)
                    {
                        Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                        if (b != null)
                        {
                            b.SetSource(fileStream);
                            SetPictureSource(b);
                            SetPictureElementSize();
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #14
0
        private async void GetPhotoButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

            // file is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                displayImage.Source = bitmapImage;
                this.DataContext = file;
            }
        }
 public Windows.UI.Xaml.Media.Imaging.BitmapImage GetBitmapSource(System.IO.Stream stream)
 {
     Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
     Windows.Storage.Streams.InMemoryRandomAccessStream ras = new Windows.Storage.Streams.InMemoryRandomAccessStream();
     stream.CopyTo(System.IO.WindowsRuntimeStreamExtensions.AsStreamForRead(ras));
     bitmapSource.SetSource(ras);
     return bitmapSource;
 }
Пример #16
0
        // Create OpenImageButton_Click to handle clicking openImageButton.
        private async void OpenImageButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            // Open a dialog box to allow opening a JPEG image.
            // The result is either a StorageFile representing the image or null if the user canceled opening.
            Windows.Storage.Pickers.FileOpenPicker pickerToOpenImage = new Windows.Storage.Pickers.FileOpenPicker();
            pickerToOpenImage.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            pickerToOpenImage.FileTypeFilter.Clear();
            pickerToOpenImage.FileTypeFilter.Add(".png");
            pickerToOpenImage.FileTypeFilter.Add(".jpg");
            Windows.Storage.StorageFile fileToOpen = await pickerToOpenImage.PickSingleFileAsync();

            // If an image has been opened...
            if (fileToOpen != null)
            {
                // Refresh imageCanvas.
                this.ImageCanvas.Children.Clear();

                // Create an image object representing the opened image.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await fileToOpen.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    bitmapImage.SetSource(fileStream);
                }
                this.ImageToAnalyze        = new Windows.UI.Xaml.Controls.Image();
                this.ImageToAnalyze.Source = bitmapImage;

                // Maximize and center imageToAnalyze in app.
                double aspectRatioOfImage       = System.Convert.ToDouble(bitmapImage.PixelWidth) / System.Convert.ToDouble(bitmapImage.PixelHeight);
                double aspectRatioOfImageCanvas = this.ImageCanvas.Width / this.ImageCanvas.Height;
                if (aspectRatioOfImage < aspectRatioOfImageCanvas)
                {
                    this.ImageToAnalyze.Height = this.ImageCanvas.Height;
                    this.ImageToAnalyze.Width  = this.ImageCanvas.Height * aspectRatioOfImage;
                    Windows.UI.Xaml.Controls.Canvas.SetLeft(this.ImageToAnalyze, (this.ImageCanvas.Width - this.ImageToAnalyze.Width) / 2);
                    Windows.UI.Xaml.Controls.Canvas.SetTop(this.ImageToAnalyze, 0);
                } // if
                else
                {
                    this.ImageToAnalyze.Width  = this.ImageCanvas.Width;
                    this.ImageToAnalyze.Height = this.ImageCanvas.Width / aspectRatioOfImage;
                    Windows.UI.Xaml.Controls.Canvas.SetLeft(this.ImageToAnalyze, 0);
                    Windows.UI.Xaml.Controls.Canvas.SetTop(this.ImageToAnalyze, (this.ImageCanvas.Height - this.ImageToAnalyze.Height) / 2);
                } // else
                this.ImageCanvas.Children.Add(this.ImageToAnalyze);

                // Add functionality relating to a mouse pointer moving over imageToAnalyze, a mouse clicking the image, and a mouse pointer passing beyond image boundaries.
                this.PositionOfLeftEdgeOfImageRelativeToLeftEdgeOfImageCanvas  = (this.ImageCanvas.Width - this.ImageToAnalyze.Width) / 2;
                this.PositionOfRightEdgeOfImageRelativeToLeftEdgeOfImageCanvas = (this.ImageCanvas.Width + this.ImageToAnalyze.Width) / 2;
                this.PositionOfTopEdgeOfImageRelativeToTopEdgeOfImageCanvas    = (this.ImageCanvas.Height - this.ImageToAnalyze.Height) / 2;
                this.PositionOfBottomEdgeOfImageRelativeToTopEdgeOfImageCanvas = (this.ImageCanvas.Height + this.ImageToAnalyze.Height) / 2;

                // Reset clickState and arrayListOfBoundingBoxEncodings.
                this.ClickState = 0;
                this.ArrayListOfBoundingBoxEncodings = new System.Collections.ArrayList();
            } // if
        }     // private async void OpenImageButton_Click
Пример #17
0
 public static BitmapImageUWP ByteToImage(byte[] imageData)
 {
     using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
     {
         using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
         {
             writer.WriteBytes(imageData);
             writer.StoreAsync().GetResults();
         }
         BitmapImageUWP image = new BitmapImageUWP();
         image.SetSource(ms);
         return(image);
     }
 }
Пример #18
0
        /// <summary>
        /// 将获取到的文件转成bitmap
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <Windows.UI.Xaml.Media.Imaging.BitmapImage> ConverToBitmapImage(Windows.Storage.StorageFile file)
        {
            var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            //Windows.Storage.Streams.IRandomAccessStream fileSreams;
            using (var fileSreams = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                bitmap.SetSource(fileSreams);
            }
            //var fileSream = await file.OpenAsync(FileAccessMode.ReadWrite);
            //var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            //bitmap.SetSource(fileSream);
            return(bitmap);
        }
        // Update the once the user has selected a device to stream to.

        private async void SourceSelected(Windows.Media.PlayTo.PlayToManager sender,
                                          Windows.Media.PlayTo.PlayToSourceSelectedEventArgs e)
        {
            await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      () =>
            {
                DisconnectButton.Click += DisconnectButtonClick;
                MessageBlock.Text       = "Streaming to " + e.FriendlyName + "...";
                DeviceBlock.Text        = e.FriendlyName + ".\nClick here to disconnect.";
                var imageBitmap         = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                imageBitmap.SetSource(e.Icon);
                IconImage.Source = imageBitmap;
            });
        }
Пример #20
0
        public async Task<string> clipboard(DataPackageView con)
        {
            string str = string.Empty;
            //文本
            if (con.Contains(StandardDataFormats.Text))
            {
                str = await con.GetTextAsync();
                return str;
            }

            //图片
            if (con.Contains(StandardDataFormats.Bitmap))
            {
                RandomAccessStreamReference img = await con.GetBitmapAsync();
                var imgstream = await img.OpenReadAsync();
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bitmap.SetSource(imgstream);

                Windows.UI.Xaml.Media.Imaging.WriteableBitmap src = new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
                src.SetSource(imgstream);

                Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(imgstream);
                Windows.Graphics.Imaging.PixelDataProvider pxprd = await decoder.GetPixelDataAsync(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, new Windows.Graphics.Imaging.BitmapTransform(), Windows.Graphics.Imaging.ExifOrientationMode.RespectExifOrientation, Windows.Graphics.Imaging.ColorManagementMode.DoNotColorManage);
                byte[] buffer = pxprd.DetachPixelData();

                str = "image";
                StorageFolder folder = await _folder.GetFolderAsync(str);

                StorageFile file = await folder.CreateFileAsync(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + (ran.Next() % 10000).ToString() + ".png", CreationCollisionOption.GenerateUniqueName);

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, fileStream);
                    encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Straight, decoder.PixelWidth, decoder.PixelHeight, decoder.DpiX, decoder.DpiY, buffer);
                    await encoder.FlushAsync();

                    str = $"![这里写图片描述](image/{file.Name})\n";
                }
            }

            //文件
            if (con.Contains(StandardDataFormats.StorageItems))
            {
                var filelist = await con.GetStorageItemsAsync();
                StorageFile file = filelist.OfType<StorageFile>().First();
                return await imgfolder(file);
            }

            return str;
        }
        public static async Task <Windows.UI.Xaml.Media.Imaging.BitmapImage> StorageFileToBitmapImage(StorageFile file)
        {
            if (file == null)
            {
                return(null);
            }

            using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bitmapImage.SetSource(fileStream);
                return(bitmapImage);
            }
        }
Пример #22
0
        private static Windows.UI.Xaml.Media.Imaging.BitmapImage GetBitmap(byte[] bytes)
        {
            var bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

            using (var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
            {
                using (var writer = new Windows.Storage.Streams.DataWriter(stream.GetOutputStreamAt(0)))
                {
                    writer.WriteBytes(bytes);
                    writer.StoreAsync().GetResults();
                    bmp.SetSource(stream);
                }
            }
            return(bmp);
        }
Пример #23
0
        public async Task LoadImageAsync()
        {
            StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(ImagePath);

            StorageFile file = await folder.GetFileAsync(ImageName);

            using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                       await file.OpenAsync(FileAccessMode.Read))
            {
                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bitmapImage.SetSource(fileStream);
                _image = bitmapImage;
            }
        }
Пример #24
0
        public static async Task ChangeBackground(string localUri, string folder)
        {
            //if (_state.IsSharpDxRendering)
            //{
            //    var br = RenderingService.BackgroundRenderer;
            //    br.ChangeBackground(localUri, folder);
            //}
            //else
            //{
            string path;

            Windows.Storage.StorageFile storageFile = null;
            if (folder == string.Empty)
            {
                path        = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
                storageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(path + localUri);
            }
            else if (folder == "PicturesLibrary")
            {
                var localUriParts = localUri.Split("\\".ToCharArray());

                var foundFolder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync(localUriParts[0]);

                storageFile = await foundFolder.GetFileAsync(localUriParts[1]);
            }
            else if (folder == "PublicPicturesLibrary")
            {
                var localUriParts = localUri.Split("\\".ToCharArray());

                var foundFolder = await Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync(localUriParts[0]);

                storageFile = await foundFolder.GetFileAsync(localUriParts[1]);
            }

            if (storageFile != null)
            {
                using (var ms = await storageFile.OpenReadAsync())
                {
                    BackgroundBitmapImage.SetSource(ms);
                    //await BackgroundBitmapImage.SetSourceAsync(ms);  //<== FAILS TO UPDATE IMAGE ON SURFACE RT (GENERATION 1) ,
                    //    doesn't throw an error (appears successful)
                }
            }


            //}
        }
        // Called when the user selects a Play To device to stream to.

        private void sourceSelectedHandler(
            Windows.Media.PlayTo.PlayToManager sender,
            Windows.Media.PlayTo.PlayToSourceSelectedEventArgs e)
        {
            if (mediaElement.Name == "iplayer")
            {
                if (!e.SupportsImage)
                {
                    messageBlock.Text += e.FriendlyName + " does not support streaming images. " +
                                         "Please select a different device.";
                    return;
                }
            }

            if (mediaElement.Name == "vplayer")
            {
                if (!e.SupportsVideo)
                {
                    messageBlock.Text += e.FriendlyName + " does not support streaming video. " +
                                         "Please select a different device.";
                    return;
                }
            }

            if (mediaElement.Name == "aplayer")
            {
                if (!e.SupportsAudio)
                {
                    messageBlock.Text += e.FriendlyName + " does not support streaming audio. " +
                                         "Please select a different device.";
                    return;
                }
            }

            Windows.Storage.Streams.IRandomAccessStream iconStream = e.Icon;
            Windows.UI.Xaml.Media.Imaging.BitmapImage   iconBitmap =
                new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            iconBitmap.SetSource(iconStream);
            playToDeviceIconImage.Source = iconBitmap;

            playToDeviceFriendlyNameBlock.Text = e.FriendlyName;
        }
Пример #26
0
        public void ShowPage()
        {//To render PDF page, finally to the image control.
         //Calculate render size.
            CalcRenderSize();
            PixelSource bitmap = new PixelSource();

            bitmap.Width  = (int)m_iRenderAreaSizeX;
            bitmap.Height = (int)m_iRenderAreaSizeY;
            Windows.Storage.Streams.IRandomAccessStreamWithContentType stream = m_SDKDocument.RenderPageAsync(bitmap, m_iStartX, m_iStartY, m_iRenderAreaSizeX, m_iRenderAreaSizeY, m_iRotation).GetResults();
            if (stream == null)
            {
                //ShowErrorLog("Error: Fail to render page.", ref new UICommandInvokedHandler(this, &demo_view::renderPage::ReturnCommandInvokedHandler),true, FSCRT_ERRCODE_ERROR);
                return;
            }
            Windows.UI.Xaml.Media.Imaging.BitmapImage bmpImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            bmpImage.SetSource(stream);
            image.Width  = (int)m_iRenderAreaSizeX;
            image.Height = (int)m_iRenderAreaSizeY;
            image.Source = bmpImage;
        }
Пример #27
0
		/// <summary>
		/// このページには、移動中に渡されるコンテンツを設定します。前のセッションからページを
		/// 再作成する場合は、保存状態も指定されます。
		/// </summary>
		/// <param name="sender">
		/// イベントのソース (通常、<see cref="NavigationHelper"/>)>
		/// </param>
		/// <param name="e">このページが最初に要求されたときに
		/// <see cref="Frame.Navigate(Type, Object)"/> に渡されたナビゲーション パラメーターと、
		/// 前のセッションでこのページによって保存された状態の辞書を提供する
		/// セッション。ページに初めてアクセスするとき、状態は null になります。</param>
		private async void navigationHelper_LoadState (object sender, LoadStateEventArgs e)
		{
			if (e.PageState != null && e.PageState.ContainsKey ("mruToken")) {
				object value = null;
				if (e.PageState.TryGetValue ("mruToken", out value)) {
					if (value != null) {
						mruToken = value.ToString ();

						var file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync (mruToken);
						if (file != null) {
							var fileStream = await file.OpenAsync (Windows.Storage.FileAccessMode.Read);
							var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage ();
							bitmapImage.SetSource (fileStream);
							displayImage.Source = bitmapImage;
							DataContext = file;
						}
					}
				}
			}
		}
Пример #28
0
        private async void _baseWebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            var bmp        = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            var base64     = e.Value.Substring(e.Value.IndexOf(",") + 1);
            var imageBytes = Convert.FromBase64String(base64);

            using (var ms = new Windows.Storage.Streams.InMemoryRandomAccessStream())
            {
                using (var writer = new Windows.Storage.Streams.DataWriter(ms.GetOutputStreamAt(0)))
                {
                    writer.WriteBytes(imageBytes);
                    await writer.StoreAsync();
                }

                bmp.SetSource(ms);
            }

            _img.Source     = bmp;
            _img.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Пример #29
0
        private async void image_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            // Set up the file picker.
            Windows.Storage.Pickers.FileOpenPicker openPicker =
                new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.ViewMode =
                Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types.
            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".jpg");

            // Open the file picker.
            Windows.Storage.StorageFile file =
                await openPicker.PickSingleFileAsync();

            // 'file' is null if user cancels the file picker.
            if (file != null)
            {
                // Open a stream for the selected file.
                // The 'using' block ensures the stream is disposed
                // after the image is loaded.
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    slikaProfila.Source = bitmapImage;
                    Glavna.slikeVIP.Add(slikaProfila);
                    dodanaSlika = true;
                }
            }
        }
        private async void GetPhotoButton_Click(object sender, RoutedEventArgs e)
        {
            // File picker APIs don't work if the app is in a snapped state.
            // If the app is snapped, try to unsnap it first. Only show the picker if it unsnaps.
            if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped ||
                Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true)
            {
                Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
                openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

                // Filter to include a sample subset of file types.
                openPicker.FileTypeFilter.Clear();
                openPicker.FileTypeFilter.Add(".bmp");
                openPicker.FileTypeFilter.Add(".png");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".jpg");

                // Open the file picker.
                Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

                // file is null if user cancels the file picker.
                if (file != null)
                {
                    // Open a stream for the selected file.
                    Windows.Storage.Streams.IRandomAccessStream fileStream =
                        await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    displayImage.Source = bitmapImage;
                    this.DataContext    = file;

                    // Add picked file to MostRecentlyUsedList and get a token.
                    mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
                }
            }
        }
Пример #31
0
        /// <summary>
        /// This method set the poster source for the MediaElement
        /// </summary>
        private async System.Threading.Tasks.Task <bool> SetPictureUrl(string PosterUrl)
        {
            try
            {
                currentPicturePath = PosterUrl;
                Windows.Storage.StorageFile file = await GetFileFromLocalPathUrl(PosterUrl);

                if (file != null)
                {
                    using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                    {
                        if (fileStream != null)
                        {
                            Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                            if (b != null)
                            {
                                b.SetSource(fileStream);
                                SetPictureSource(b);
                                SetPictureElementSize();

                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    await SetDefaultPicture();

                    LogMessage("Failed to load poster: " + PosterUrl);
                    return(true);
                }
            }
            catch (Exception e)
            {
                LogMessage("Exception while loading poster: " + PosterUrl + " - " + e.Message);
            }

            return(false);
        }
Пример #32
0
        private async void photo_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.Desktop;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".gif");

            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

                Windows.UI.Xaml.Media.Imaging.BitmapImage bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                bmp.SetSource(stream);
                this.image.Source = bmp;
            }
        }
Пример #33
0
        async private void DisplayImage(Windows.Storage.IStorageItem file, int index)
        {
            try
            {
                var sFile = (Windows.Storage.StorageFile)file;
                Windows.Storage.Streams.IRandomAccessStream imageStream =
                    await sFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                Windows.UI.Xaml.Media.Imaging.BitmapImage imageBitmap =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                imageBitmap.SetSource(imageStream);
                var element = new Image();
                element.Source = imageBitmap;
                element.Height = 100;
                Thickness margin = new Thickness();
                margin.Top     = index * 100;
                element.Margin = margin;
                filescanvas.Children.Add(element);
            }
            catch (Exception e)
            {
                WriteMessageText(e.Message + "\n");
            }
        }
Пример #34
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="navigationParameter">The parameter value passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
 /// </param>
 /// <param name="pageState">A dictionary of state preserved by this page during an earlier
 /// session.  This will be null the first time a page is visited.</param>
 protected async override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
 {
     if (pageState != null && pageState.ContainsKey("mruToken"))
     {
         object value = null;
         if (pageState.TryGetValue("mruToken", out value))
         {
             if (value != null)
             {
                 mruToken = value.ToString();
                 //reopen the file with the stored token.
                 Windows.Storage.StorageFile file = await Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(mruToken);
                 if (file != null)
                 {
                     Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                     Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                     bitmapImage.SetSource(fileStream);
                     displayImage.Source = bitmapImage;
                     this.DataContext = file;
                 }
             }
         }
     }
 }
Пример #35
0
 private void InitBackground()
 {
     if (App.MainPageBackgroundImageStream != null)
     {
         var backgroundImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
         backgroundImage.SetSource(App.MainPageBackgroundImageStream);
         backgoundBrush.ImageSource = backgroundImage;
     }
     else
     {
         Uri imageUri = new Uri(CareConstDefine.MainPageBackgroundURI);
         var backgroundImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(imageUri);
         backgoundBrush.ImageSource = backgroundImage;
     }
 }
Пример #36
0
        private async void GetPhoto_Click(object sender, RoutedEventArgs e)
        {
            //File picker APIs don't work if the app is in a snapped state.
            //Try to unsnap the app first.  only launch the picker if it unsnapped

            if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped ||
                Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true)
            {
                Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
                openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
                openPicker.FileTypeFilter.Clear();
                openPicker.FileTypeFilter.Add(".bmp");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".png");

                Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

                if (file != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    displayImage.Source = bitmapImage;
                    this.DataContext = file;

                    mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
                }
            }
        }
Пример #37
0
		private async void GetPhotoButton_Click (object sender, RoutedEventArgs e)
		{
			var openPicker = new Windows.Storage.Pickers.FileOpenPicker ();
			openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
			openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

			openPicker.FileTypeFilter.Clear ();
			openPicker.FileTypeFilter.Add (".bmp");
			openPicker.FileTypeFilter.Add (".png");
			openPicker.FileTypeFilter.Add (".jpeg");
			openPicker.FileTypeFilter.Add (".jpg");

			var file = await openPicker.PickSingleFileAsync ();

			if (file != null) {
				var fileStream = await file.OpenAsync (Windows.Storage.FileAccessMode.Read);
				var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage ();
				bitmapImage.SetSource (fileStream);
				displayImage.Source = bitmapImage;
				DataContext = file;
			}

			mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add (file);
		}
Пример #38
0
        // Open the image picker
        private async void BrowseImage(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.ViewMode = PickerViewMode.Thumbnail;

            // Set the file extensions
            picker.FileTypeFilter.Clear();
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".bmp");
            picker.FileTypeFilter.Add(".png");

            image = await picker.PickSingleFileAsync();

            if (image != null)
            {
                // Open a stream for the selected file.
                Windows.Storage.Streams.IRandomAccessStream fileStream = await image.OpenAsync(Windows.Storage.FileAccessMode.Read);

                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                imagePreview.Source = bitmapImage;
            }
        }
Пример #39
0
        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker filePicker = new Windows.Storage.Pickers.FileOpenPicker();
            filePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".jpeg");
            filePicker.FileTypeFilter.Add(".png");
            filePicker.FileTypeFilter.Add(".bmp");
            filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;

            StorageFile file = await filePicker.PickSingleFileAsync();
            if (file != null)
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                     await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    Image.Source = bitmapImage;
                    ImageName = file.Name;
                    ImagePath = file.Path;
                    Windows.Storage.StorageFolder targetFolder = await StorageFolder.GetFolderFromPathAsync(Models.TodoItem.ImagePath);
                    await file.CopyAsync(targetFolder, ImageName, NameCollisionOption.ReplaceExisting);
                }
            }
        }
Пример #40
0
        private async void SetExtraPropertiesAsync(StorageItemInfo itemInfo)
        {
            if (itemInfo.IsFile)
            {
                //파일 용량 조회
                var file = await itemInfo.GetStorageFileAsync();

                if (file != null)
                {
                    //System.Diagnostics.Debug.WriteLine(file.DisplayName);
                    var bi = await file.GetBasicPropertiesAsync();

                    //파일 크기 설정
                    itemInfo.Size = bi.Size;
                    //썸네일 로드
                    this.LoadThumbnailAsync(itemInfo, _ThumbnailListInCurrentFolder, Settings.Thumbnail.UseUnsupportedDLNAFile);
                    //자막 목록 설정
                    if (_CurrentSubtitleFileList != null && _CurrentSubtitleFileList.Any())
                    {
                        itemInfo.SubtitleList = _CurrentSubtitleFileList.Where(x => x.Contains(System.IO.Path.GetFileNameWithoutExtension(itemInfo.Name).ToUpper())).ToList();
                    }
                }
            }
            else
            {
                var folder = await itemInfo.GetStorageFolderAsync();

                if (folder != null)
                {
                    itemInfo.DateCreated = folder.DateCreated;

                    //비디오 파일 갯수를 알아내기 위한 필터링 옵션
                    var queryResult = folder.CreateFileQueryWithOptions(_VideoFileQueryOptions);
                    itemInfo.FileCount = (int)await queryResult.GetItemCountAsync();

                    var folderCount = await folder.CreateFolderQuery().GetItemCountAsync();

                    if (itemInfo.FileCount > 0)
                    {
                        itemInfo.FileCountDescription = itemInfo.FileCount.ToString() + (folderCount > 0 ? "+" : string.Empty);
                    }
                    else
                    {
                        itemInfo.FileCountDescription = "0" + (folderCount > 0 ? "*" : string.Empty);
                    }

                    if (itemInfo.FileCount > 0)
                    {
                        var fileList = await queryResult.GetFilesAsync();

                        List <ImageSource> imageSourceList = new List <ImageSource>();

                        List <Thumbnail> thumbnailList = new List <Thumbnail>();
                        ThumbnailDAO.LoadThumnailInFolder(itemInfo.Path, thumbnailList);

                        for (int i = 0; i < fileList.Count; i++)
                        {
                            //썸네일 로드
                            var imgSrc = await GetThumbnailAsync(fileList[i], thumbnailList, Settings.Thumbnail.UseUnsupportedDLNAFolder);

                            if (imgSrc != null)
                            {
                                imageSourceList.Add(imgSrc);
                            }
                            //4장의 이미지를 채우지 못할 것으로 확신되거나, 이미 4장을 채운경우 정지
                            if (((imageSourceList.Count > 0 && imageSourceList.Count >= 4) ||
                                 (itemInfo.FileCount - (i + 1) + imageSourceList.Count < 4)) && imageSourceList.Count > 0)
                            {
                                break;
                            }
                        }

                        itemInfo.ImageItemsSource = imageSourceList;
                    }
                    else if (!_FolderStack.Any())
                    {
                        //NAS아이콘 추출
                        ImageSource imageSource = null;
                        var         thumb       = await folder.GetThumbnailAsync(ThumbnailMode.SingleItem);

                        if (thumb?.Type == ThumbnailType.Image)
                        {
                            //썸네일 설정
                            await DispatcherHelper.RunAsync(() =>
                            {
                                var bi = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                bi.SetSource(thumb);
                                imageSource               = bi;
                                itemInfo.IsFullFitImage   = false;
                                itemInfo.ImageItemsSource = imageSource;
                            });
                        }
                    }
                }
            }
        }
        private async void GetPhotoButton_Click(object sender, RoutedEventArgs e)
        {
            // File picker APIs don't work if the app is in a snapped state.
            // If the app is snapped, try to unsnap it first. Only show the picker if it unsnaps.
            if (Windows.UI.ViewManagement.ApplicationView.Value != Windows.UI.ViewManagement.ApplicationViewState.Snapped ||
                 Windows.UI.ViewManagement.ApplicationView.TryUnsnap() == true)
            {
                Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
                openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

                // Filter to include a sample subset of file types.
                openPicker.FileTypeFilter.Clear();
                openPicker.FileTypeFilter.Add(".bmp");
                openPicker.FileTypeFilter.Add(".png");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".jpg");

                // Open the file picker.
                Windows.Storage.StorageFile file = await openPicker.PickSingleFileAsync();

                // file is null if user cancels the file picker.
                if (file != null)
                {
                    // Open a stream for the selected file.
                    Windows.Storage.Streams.IRandomAccessStream fileStream =
                        await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    displayImage.Source = bitmapImage;
                    this.DataContext = file;

                    // Add picked file to MostRecentlyUsedList and get a token.
                    mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file);
                }
            }

        }
Пример #42
0
        /// <summary>
        /// This method set the poster source for the MediaElement 
        /// </summary>
        private async System.Threading.Tasks.Task<bool> SetPosterUrl(string PosterUrl)
        {
            if (IsPicture(PosterUrl))
            {
                if (IsLocalFile(PosterUrl))
                {
                    try
                    {
                        Windows.Storage.StorageFile file = await GetFileFromLocalPathUrl(PosterUrl);
                        if (file != null)
                        {
                            using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                            {
                                if (fileStream != null)
                                {
                                    Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                    if (b != null)
                                    {
                                        b.SetSource(fileStream);
                                        SetPictureSource(b);
                                        SetPictureElementSize();
                                        return true;
                                    }
                                }
                            }
                        }
                        else
                            LogMessage("Failed to load poster: " + PosterUrl);

                    }
                    catch (Exception e)
                    {
                        LogMessage("Exception while loading poster: " + PosterUrl + " - " + e.Message);
                    }
                }
                else
                {
                    try
                    {

                        // Load the bitmap image over http
                        Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
                        Windows.Storage.Streams.InMemoryRandomAccessStream ras = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                        using (var stream = await httpClient.GetInputStreamAsync(new Uri(PosterUrl)))
                        {
                            if (stream != null)
                            {
                                await stream.AsStreamForRead().CopyToAsync(ras.AsStreamForWrite());
                                ras.Seek(0);
                                var b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                if (b != null)
                                {
                                    await b.SetSourceAsync(ras);
                                    SetPictureSource(b);
                                    SetPictureElementSize();
                                    return true;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception: " + e.Message);
                    }
                }
            }

            return false;
        }
Пример #43
0
 public async Task LoadImageAsync()
 {
     StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(ImagePath);
     StorageFile file = await folder.GetFileAsync(ImageName);
     using (Windows.Storage.Streams.IRandomAccessStream fileStream =
             await file.OpenAsync(FileAccessMode.Read))
     {
         // Set the image source to the selected bitmap.
         Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
             new Windows.UI.Xaml.Media.Imaging.BitmapImage();
         bitmapImage.SetSource(fileStream);
         _image = bitmapImage;
     }
 }