Esempio n. 1
0
        public Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = default(CancellationToken))
        {
            Windows.UI.Xaml.Media.ImageSource image = null;

            var imageImageSource = imagesource as SKImageImageSource;

            if (imageImageSource != null)
            {
                image = imageImageSource.Image?.ToWriteableBitmap();
            }

            var bitmapImageSource = imagesource as SKBitmapImageSource;

            if (bitmapImageSource != null)
            {
                image = bitmapImageSource.Bitmap?.ToWriteableBitmap();
            }

            var pixmapImageSource = imagesource as SKPixmapImageSource;

            if (pixmapImageSource != null)
            {
                image = pixmapImageSource.Pixmap?.ToWriteableBitmap();
            }

            var pictureImageSource = imagesource as SKPictureImageSource;

            if (pictureImageSource != null)
            {
                image = pictureImageSource.Picture?.ToWriteableBitmap(pictureImageSource.Dimensions);
            }

            return(Task.FromResult(image));
        }
Esempio n. 2
0
 public static SizeRequest GetDesiredSize(this WinImageSource source)
 {
     if (source is BitmapSource bitmap)
     {
         return(new SizeRequest(
                    new Size
         {
             Width = bitmap.PixelWidth,
             Height = bitmap.PixelHeight
         }));
     }
     else if (source is CanvasImageSource canvas)
     {
         return(new SizeRequest(
                    new Size
         {
             Width = canvas.SizeInPixels.Width,
             Height = canvas.SizeInPixels.Height
         }));
     }
     else
     {
         throw new InvalidCastException($"\"{source.GetType().FullName}\" is not supported.");
     }
 }
        public async Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken = new CancellationToken())
        {
            Windows.UI.Xaml.Media.ImageSource image = null;
            var filesource = imagesource as FileImageSource;

            if (filesource != null)
            {
                string file = filesource.File;
                if (System.IO.Path.IsPathRooted(file))
                {
                    using (Windows.Storage.Streams.IRandomAccessStream fileStream = await(await Windows.Storage.StorageFile.GetFileFromPathAsync(file)).OpenAsync(Windows.Storage.FileAccessMode.Read))
                    {
                        // Set the image source to the selected bitmap.
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(fileStream);
                        image = bitmapImage;
                    }
                }
                else
                {
                    image = new BitmapImage(new Uri("ms-appx:///" + file));
                }
            }

            return(image);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets current users profile.
        /// </summary>
        /// <returns>
        /// The current users profile.
        /// </returns>
        public async Task <ProfileUser> GetProfile()
        {
            try
            {
                if (Profile != null)
                {
                    return(Profile);
                }
                else
                {
                    var spotify = await Authentication.GetSpotifyClientAsync();

                    if (spotify != null)
                    {
                        var user = await spotify.UserProfile.Current();

                        Windows.UI.Xaml.Media.ImageSource image = null;
                        if (user.Images != null)
                        {
                            image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(user.Images.FirstOrDefault().Url));
                        }
                        Profile = new ProfileUser(user.Id, user.DisplayName, image);
                        return(Profile);
                    }
                    return(null);
                }
            }
            catch (Exception e)
            {
                ViewModels.Helpers.DisplayDialog("Error", e.Message);
                return(null);
            }
        }
Esempio n. 5
0
        private static System.Windows.Media.ImageSource?ToWpfImageSource(this Windows.UI.Xaml.Media.ImageSource imageSource)
        {
            if (imageSource is Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapSource)
            {
                new System.Windows.Media.Imaging.BitmapImage(bitmapSource.UriSource);
            }

            // TODO: Support more image sources.
            return(null);
        }
        public Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken = new CancellationToken())
        {
            Windows.UI.Xaml.Media.ImageSource image = null;
            if (imagesource is FileImageSource filesource)
            {
                UpdateImageDirectory(filesource);
                string file = filesource.File;
                image = new BitmapImage(new Uri("ms-appx:///" + file));
            }

            return(Task.FromResult(image));
        }
Esempio n. 7
0
 public UserHubModel(Newtonsoft.Json.Linq.JObject o, ImageSource image)
 {
     UserAvatar             = image;
     UserName               = o.Value <string>("username");
     FeedNum                = o.Value <int>("feed");
     FollowNum              = o.Value <int>("follow");
     FansNum                = o.Value <int>("fans");
     LevelNum               = o.Value <int>("level");
     NextLevelExperience    = o.Value <int>("next_level_experience");
     NextLevelPercentage    = o.Value <double>("next_level_percentage");
     LevelTodayMessage      = o.Value <string>("level_today_message");
     NextLevelNowExperience = $"{nextLevelPercentage / 100 * nextLevelExperience:F0}/{nextLevelExperience}";
 }
        public Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesource, CancellationToken cancellationToken = new CancellationToken())
        {
            Windows.UI.Xaml.Media.ImageSource image = null;
            var filesource = imagesource as FileImageSource;

            if (filesource != null)
            {
                string file = filesource.File;
                image = new BitmapImage(new Uri("ms-appx:///" + file));
            }

            return(Task.FromResult(image));
        }
Esempio n. 9
0
        public async void ce()
        {
            Windows.Storage.Pickers.FileOpenPicker pick;
            pick = new Windows.Storage.Pickers.FileOpenPicker();
            pick.FileTypeFilter.Add(".jpg");
            Windows.Storage.StorageFile file = await pick.PickSingleFileAsync();

            if (file != null)
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage temp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await temp.SetSourceAsync(await file.OpenAsync(Windows.Storage.FileAccessMode.Read));

                img = temp;
            }
        }
Esempio n. 10
0
 private void setsource(TextReader tr, float disinfo)
 {
     if (canuse(this.ActualHeight) && canuse(this.ActualWidth))
     {
         var  svg = NGraphics.Graphic.LoadSvg(tr);
         Size size;
         if (UseRecommendedSize)
         {
             size = svg.Size;
         }
         else
         {
             size = new Size(ActualWidth, ActualHeight);
         }
         var canvas = Platforms.Current.CreateImageCanvas(size, scale: disinfo / 96f);
         svg.Draw(canvas);
         images = (canvas.GetImage() as WICBitmapSourceImage).SaveAsSoftwareBitmapSource();
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Checks if the current user has been authenticated with a valid access token if any.
        /// </summary>
        /// <returns>
        /// True if authenticated, false othewise
        /// </returns>
        public async Task <bool> IsAuthenticated()
        {
            try
            {
                var currentUser = await Authentication.IsAuthenticated();

                Windows.UI.Xaml.Media.ImageSource image = null;
                if (currentUser.Images != null)
                {
                    image = new BitmapImage(new Uri(currentUser.Images.FirstOrDefault().Url));
                }
                Profile = new ProfileUser(currentUser.Id, currentUser.DisplayName, image);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 /// <summary>
 /// Creates a <see cref="ImageSource"/> from <see cref="Windows.UI.Xaml.Media.ImageSource"/>.
 /// </summary>
 /// <param name="args">The <see cref="Windows.UI.Xaml.Media.ImageSource"/> instance containing the event data.</param>
 /// <returns><see cref="ImageSource"/></returns>
 public static ImageSource FromImageSource(Windows.UI.Xaml.Media.ImageSource args)
 {
     return(new ImageSource(args));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageSource"/> class, a
 /// Wpf-enabled wrapper for <see cref="Windows.UI.Xaml.Media.ImageSource"/>
 /// </summary>
 public ImageSource(Windows.UI.Xaml.Media.ImageSource instance)
 {
     this.UwpInstance = instance;
 }
Esempio n. 14
0
 public void SetImage(String path)
 {
     this._image     = null;
     this._imagePath = path;
 }
Esempio n. 15
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            Windows.UI.Xaml.Media.ImageSource source = null;
            string strType = (string)value;

            switch (strType)
            {
            case "文件夹":
                source = new BitmapImage(new Uri("ms-appx:///Assets/folder.png"));
                break;

            case "exe":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/exe.png"));
                break;

            case "dll":
            case "sys":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/dll.png"));
                break;

            case "ini":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/ini.png"));
                break;

            case "pdf":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/pdf.png"));
                break;

            case "rtf":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/rtf.png"));
                break;

            case "mp3":
            case "wav":
            case "flac":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/music.png"));
                break;

            case "php":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/php.png"));
                break;

            case "cpp":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/cpp.png"));
                break;

            case "js":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/js.png"));
                break;

            case "doc":
            case "docx":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/word.png"));
                break;

            case "xls":
            case "xlsx":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/excel.png"));
                break;

            case "ppt":
            case "pptx":
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/ppt.png"));
                break;

            default:
                source = new BitmapImage(new Uri("ms-appx:///Assets/FileTypeIcon/default.png"));
                break;
            }
            return(source);
        }
Esempio n. 16
0
 void IImageVisualElementRenderer.SetImage(Windows.UI.Xaml.Media.ImageSource image)
 {
     Control.Source = image;
 }
Esempio n. 17
0
        /// <summary>
        /// Merges 2 or more playlists into 1 new playlist.
        /// </summary>
        /// <param name="name">
        /// The name of the new playlist.
        /// </param>
        /// <param name="playlists">
        /// The list of playlists to merge.
        /// </param>
        /// <param name="base64Jpg">
        /// The playlist cover in base64 string format (Optional).
        /// </param>
        /// <param name="img">
        /// The cover image if using a custom cover image for the playlist.
        /// </param>
        /// <returns>
        /// The newly create playlist.
        /// </returns>
        public async Task <Playlist> MergeSpotifyPlaylists(string name, string description, IEnumerable <Playlist> playlists, string base64Jpg = null, BitmapImage img = null)
        {
            try
            {
                if (playlists.Count() <= 1)
                {
                    return(null);
                }

                var spotify = await Authentication.GetSpotifyClientAsync();

                List <Track> tracks = new List <Track>();

                foreach (var playlist in playlists)
                {
                    var items1 = await GetSpotifyTracks(playlist.Id);

                    if (items1 != null && items1.Count < playlist.ItemsCount)
                    {
                        //handle duplicates
                        var items2 = await GetOtherSpotifyTracks();

                        if (items2 != null)
                        {
                            foreach (var track in items2)
                            {
                                if (!tracks.Any(c => c.Id == track.Id))
                                {
                                    tracks.Add(track);
                                }
                            }
                        }
                    }
                    else if (items1 != null)
                    {
                        foreach (var track in items1)
                        {
                            if (!tracks.Any(c => c.Id == track.Id))
                            {
                                tracks.Add(track);
                            }
                        }
                    }
                }

                int itemsCount = 0;
                Windows.UI.Xaml.Media.ImageSource image = null;
                var item = await CreateSpotifyPlaylist(name, description, tracks, base64Jpg);

                if (item != null)
                {
                    if (item.Images != null && item.Images.Count > 0)
                    {
                        image = new BitmapImage(new Uri(item.Images.FirstOrDefault().Url));
                    }
                    else if (img != null)
                    {
                        image = img;
                    }

                    if (item.Tracks != null)
                    {
                        itemsCount = item.Tracks.Total;
                    }

                    return((await ConvertPlaylists(new List <FullPlaylist> {
                        item
                    })).FirstOrDefault());
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }