Esempio n. 1
0
        public static Task <SKImage?> ToSKImageAsync(this ImageSource imageSource, CancellationToken cancellationToken = default)
        {
            if (imageSource == null)
            {
                throw new ArgumentNullException(nameof(imageSource));
            }

            return(imageSource switch
            {
                // 1. first try SkiaSharp sources
                SKImageImageSource iis => FromSkia(iis.Image),
                SKBitmapImageSource bis => FromSkia(SKImage.FromBitmap(bis.Bitmap)),
                SKPixmapImageSource xis => FromSkia(SKImage.FromPixels(xis.Pixmap)),
                SKPictureImageSource pis => FromSkia(SKImage.FromPicture(pis.Picture, pis.Dimensions)),

                // 2. then try Stream sources
                StreamImageSource stream => FromStream(stream.Stream.Invoke(cancellationToken)),
                UriImageSource uri => FromStream(uri.GetStreamAsync(cancellationToken)),

                // 3. finally, use the handlers
                FileImageSource file => FromHandler(PlatformToSKImageAsync(file, cancellationToken)),
                FontImageSource font => FromHandler(PlatformToSKImageAsync(font, cancellationToken)),

                // 4. all is lost
                _ => throw new ArgumentException("Unable to determine the type of image source.", nameof(imageSource))
            });
        public async Task ImageReturnsSameImage()
        {
            using var image = SKImage.Create(new SKImageInfo(100, 100));

            var source = new SKImageImageSource {
                Image = image
            };

            var result = await source.ToSKImageAsync();

            Assert.NotNull(result);

            Assert.Equal(image, result);
        }
Esempio n. 3
0
        public PreviewScreen()
        {
            Navigation.RemovePage(App.lastPage);
            App.lastPage = this;
            InitializeComponent();
            SKImageImageSource source = new SKImageImageSource();

            source.Image        = App.playerDrawings[App.playerDrawings.Count() - 1];
            PreviewImage.Source = source;
            CheckOut.Text       = String.Format("Check out what {0} drew", App.playerNames[App.playerNames.Count() - 2]);
            // now start a timer, maybe they press ready? or maybe we just start it? idk
            currentTime     = App.previewTime;
            TimerLabel.Text = currentTime.ToString();
            timer           = new Timer(1000);
            timer.Elapsed  += CheckTimer;
            timer.Enabled   = true;
        }
Esempio n. 4
0
        public FinalScreen()
        {
            Navigation.RemovePage(App.lastPage);
            App.lastPage = this;
            InitializeComponent();

            List <SKImageImageSource> playerImages = new List <SKImageImageSource>();

            for (int i = 0; i < App.playerDrawings.Count; i++)
            {
                SKImageImageSource source = new SKImageImageSource();
                source.Image = App.playerDrawings[i];
                playerImages.Add(source);
            }

            MyCarousel.ItemsSource = playerImages;
        }