Esempio n. 1
0
        public static async Task <TileImageCollection> GetTileImages(string pageUrl)
        {
            try
            {
                if (pageUrl.ToLower().StartsWith("https://open.spotify.com/playlist/"))
                {
                    string playlistId = pageUrl.Substring("https://open.spotify.com/playlist/".Length);
                    if (playlistId.Contains('/'))
                    {
                        playlistId = playlistId.Substring(0, playlistId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetPlaylistArt(playlistId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
                else if (pageUrl.ToLower().StartsWith("https://open.spotify.com/artist/"))
                {
                    string artistId = pageUrl.Substring("https://open.spotify.com/artist/".Length);
                    if (artistId.Contains('/'))
                    {
                        artistId = artistId.Substring(0, artistId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetArtistArt(artistId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
                else if (pageUrl.ToLower().StartsWith("https://open.spotify.com/album/"))
                {
                    string albumId = pageUrl.Substring("https://open.spotify.com/album/".Length);
                    if (albumId.Contains('/'))
                    {
                        albumId = albumId.Substring(0, albumId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetAlbumArt(albumId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
            }
            catch (Exception ex)
            {
                logger.Info("GetTileImage failed: " + ex.ToString());
            }

            return(null);
        }
Esempio n. 2
0
        private static async Task <TileImageCollection> CreateTileImages(Uri imageUri)
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(imageUri);

            var decoder = await BitmapDecoder.CreateAsync(await file.OpenAsync(FileAccessMode.Read));

            WriteableBitmap squareBitmap, wideBitmap;

            (Point squarePoint, Size squareSize) = GetCropDetails(decoder, 1.0);
            squareBitmap = await CropBitmap.GetCroppedBitmapAsync(file, squarePoint, squareSize, 1.0);

            (Point widePoint, Size wideSize) = GetCropDetails(decoder, 310.0 / 150.0);
            wideBitmap = await CropBitmap.GetCroppedBitmapAsync(file, widePoint, wideSize, 1.0);

            var squareFile = await ImageSaveHelper.SaveWritableBitmapToTileImageCache(squareBitmap, "square");

            var wideFile = await ImageSaveHelper.SaveWritableBitmapToTileImageCache(wideBitmap, "wide");

            return(new TileImageCollection
            {
                SquareImage = squareFile,
                WideImage = wideFile,
            });
        }