예제 #1
0
        private async void Button_ClickAsync(object sender, RoutedEventArgs e)
        {
            string textFile = "";

            //name of file to store album info
            if (albumName.Text != "")
            {
                textFile = albumName.Text + ".txt";

                var picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".jpeg");
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".bmp");

                var files = await picker.PickMultipleFilesAsync();

                try
                {
                    //Add pictures to album file
                    await AlbumHelper.AddPictures(files, textFile);
                }

                catch (Exception ex)
                {
                    var dialog = new MessageDialog(ex.Message);
                    await dialog.ShowAsync();
                }

                this.Frame.Navigate(typeof(AlbumPage));
            }
            else
            {
                var dialog = new MessageDialog("Please enter an album name");
                await dialog.ShowAsync();
            }
        }
예제 #2
0
        private static async Task AddPictureToAlbum(string filePath, string textFileName)
        {
            char[]      charSeparators = new char[] { '.' };
            var         name           = textFileName.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries);
            StorageFile storageFile    = null;

            try
            {
                storageFile = await StorageFile.GetFileFromPathAsync(filePath);
            }
            catch (UnauthorizedAccessException)
            {
                throw new Exception("Access denied to the folder");
            }

            // Create a bitmap
            var bitmapImage = new BitmapImage();

            using (var stream = await storageFile.OpenAsync(FileAccessMode.Read))
            {
                bitmapImage.SetSource(stream);
            }

            //ObservableCollection<AlbumPic> Album = new ObservableCollection<AlbumPic>();

            // Create Picture object
            var pic = new AlbumHelper();

            pic.Path1        = storageFile.Path;
            pic.ImageSource1 = bitmapImage;
            pic.AlbumName    = name[0];

            //Add picture to album
            Album.Add(pic);

            // Add Album object to the global observable collection
            // Albums.Add(Album);
        }