public async Task Create(CompositionGraphicsDevice device) { _random = new Random(); _device = device; _allUris = new List<Uri>(); StorageFolder useFolder = await GetPhotosFolder(); await AddFiles(useFolder); // Ensure that each file is only listed once for (int a = 0; a < _allUris.Count - 1; a++) { for (int b = a + 1; b < _allUris.Count; b++) { if (String.Equals( _allUris[a].LocalPath, _allUris[b].LocalPath, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allUris.Count]; int index = 0; foreach (var uri in _allUris) { _allPhotos[index++] = new Photo(uri, _device); } // Rather than continously picking random photos, we want to shuffle all photos to // ensure that we don't unnecessarily duplicate photos. Otherwise, statistically, we // will have more duplicated photos than necessary, and not even load some photos. ShufflePhotos(); }
public async Task Create(CompositionImageFactory imageFactory) { _random = new Random(); _imageFactory = imageFactory; _allFiles = new List <StorageFile>(); // Search pictures to build File collection of images. StorageFolder picturesFolder = KnownFolders.PicturesLibrary; StorageFolder useFolder = picturesFolder; try { var item = await picturesFolder.TryGetItemAsync("Demo"); if ((item != null) && item.IsOfType(StorageItemTypes.Folder)) { StorageFolder demosFolder = (StorageFolder)item; useFolder = demosFolder; } } catch (Exception) { } await AddFiles(useFolder); // Ensure that each file is only listed once for (int a = 0; a < _allFiles.Count - 1; a++) { for (int b = a + 1; b < _allFiles.Count; b++) { if (String.Equals( _allFiles[a].Path, _allFiles[b].Path, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allFiles.Count]; int index = 0; foreach (var file in _allFiles) { _allPhotos[index++] = new Photo(file, _imageFactory); } // Rather than continously picking random photos, we want to shuffle all photos to // ensure that we don't unnecessarily duplicate photos. Otherwise, statistically, we // will have more duplicated photos than necessary, and not even load some photos. ShufflePhotos(); }
public async Task Create(CompositionImageFactory imageFactory) { _random = new Random(); _imageFactory = imageFactory; _allFiles = new List<StorageFile>(); // Search pictures to build File collection of images. StorageFolder picturesFolder = KnownFolders.PicturesLibrary; StorageFolder useFolder = picturesFolder; try { var item = await picturesFolder.TryGetItemAsync("Demo"); if ((item != null) && item.IsOfType(StorageItemTypes.Folder)) { StorageFolder demosFolder = (StorageFolder)item; useFolder = demosFolder; } } catch (Exception) { } await AddFiles(useFolder); // Ensure that each file is only listed once for (int a = 0; a < _allFiles.Count - 1; a++) { for (int b = a + 1; b < _allFiles.Count; b++) { if (String.Equals( _allFiles[a].Path, _allFiles[b].Path, StringComparison.OrdinalIgnoreCase)) { Debug.Assert(false, "Same filename appears twice"); } } } // Build a Photo for each of the given uris. _allPhotos = new Photo[_allFiles.Count]; int index = 0; foreach (var file in _allFiles) { _allPhotos[index++] = new Photo(file, _imageFactory); } // Rather than continously picking random photos, we want to shuffle all photos to // ensure that we don't unnecessarily duplicate photos. Otherwise, statistically, we // will have more duplicated photos than necessary, and not even load some photos. ShufflePhotos(); }
private void ProcessImageLoaded(Photo startPhoto) { // Once the image is loaded, assign it to a tile if it has actual content: // - Indirectly, this handles if we had errors during loading. var size = startPhoto.ThumbnailImage.Size; if ((size.Width > 0) && (size.Height > 0)) { var selectedTile = _allTiles[_currentTileIndex]; if (selectedTile.Photo == null) { selectedTile.Photo = startPhoto; } else { var nearestEmpty = FindNearestEmptyTile(selectedTile); if (nearestEmpty != null) { Debug.Assert(nearestEmpty.Photo == null); nearestEmpty.Photo = startPhoto; } } // We cannot reduce "_emptyTileCount" until after the CompleteLoadAsync() completes // successfully, in case there is a problem loading any images. This means that we // may load more images than get immediately used. --_emptyTileCount; } // Now that we've loaded a new Photo, if we still have empty tiles, begin loading // the next photo: if (_emptyTileCount > 0) { LoadNextPhoto(); } else { foreach (Tile checkTile in _allTiles) { if (checkTile.Photo == null) { Debug.Assert(false); } var checkImage = checkTile.Photo.ThumbnailImage; if ((checkImage.Size.Width <= 0) || (checkImage.Size.Height <= 0)) { Debug.Assert(false); } } } }