コード例 #1
0
        public static Size GetImageSourceSize(this WImageSource source)
        {
            if (source is null)
            {
                return(Size.Zero);
            }
            else if (source is BitmapSource bitmap)
            {
                return(new Size
                {
                    Width = bitmap.PixelWidth,
                    Height = bitmap.PixelHeight
                });
            }
            else if (source is CanvasImageSource canvas)
            {
                return(new Size
                {
                    Width = canvas.Size.Width,
                    Height = canvas.Size.Height
                });
            }

            throw new InvalidCastException($"\"{source.GetType().FullName}\" is not supported.");
        }
コード例 #2
0
        public Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesoure, CancellationToken cancelationToken)
        {
            //BitmapImage bitmapImage = null;
            //UriImageSource uriImageSource = imagesoure as UriImageSource;
            //if (uriImageSource != null && uriImageSource.Uri != null)
            //{
            //    using (Stream stream = await uriImageSource.GetStreamAsync(cancelationToken))
            //    {
            //        if (stream != null && stream.CanRead)
            //        {
            //            IRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();
            //            using (var inputStream = stream.AsInputStream())
            //            {
            //                await RandomAccessStream.CopyAsync(inputStream, inMemoryStream);
            //            }
            //            inMemoryStream.Seek(0);

            //            bitmapImage = new BitmapImage();
            //            bitmapImage.SetSource(inMemoryStream);
            //        }
            //    }
            //}
            //return bitmapImage;
            Windows.UI.Xaml.Media.ImageSource bitmapImage = null;
            UriImageSource fileImageSource = imagesoure as UriImageSource;

            if (fileImageSource != null)
            {
                bitmapImage = new BitmapImage(fileImageSource.Uri);
            }
            return(Task.FromResult(bitmapImage));
        }
コード例 #3
0
 public TodoItem(string title, string description, DateTime date, ImageSource imagesource)
 {
     this.id          = Guid.NewGuid().ToString(); //生成id
     this.title       = title;
     this.description = description;
     this.date        = date;
     this.imagesource = imagesource;
 }
コード例 #4
0
 public TodoItem(string title, string description, ImageSource image, DateTime date)
 {
     this.id          = Guid.NewGuid().ToString();
     this.title       = title;
     this.description = description;
     this.completed   = false;
     this.date        = date;
     this.image       = image;
 }
コード例 #5
0
        public Task <Windows.UI.Xaml.Media.ImageSource> LoadImageAsync(ImageSource imagesoure, CancellationToken cancelationToken)
        {
            Windows.UI.Xaml.Media.ImageSource bitmapImage = null;
            FileImageSource fileImageSource = imagesoure as FileImageSource;

            if (fileImageSource != null)
            {
                string file = fileImageSource.File;
                bitmapImage = new BitmapImage(new Uri(string.Concat("/", file), UriKind.Relative));
            }
            return(Task.FromResult(bitmapImage));
        }
コード例 #6
0
ファイル: ImageRenderer.cs プロジェクト: knocte/Xamarin.Forms
        async Task UpdateSource()
        {
            Element.SetIsLoading(true);

            ImageSource         source = Element.Source;
            IImageSourceHandler handler;

            if (source != null && (handler = Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null)
            {
                Windows.UI.Xaml.Media.ImageSource imagesource = null;

                try
                {
                    imagesource = await handler.LoadImageAsync(source);
                }
                catch (OperationCanceledException)
                {
                    imagesource = null;
                }
                catch (Exception ex)
                {
                    Log.Warning("Image Loading", $"Error updating image source: {ex}");
                }

                // In the time it takes to await the imagesource, some zippy little app
                // might have disposed of this Image already.
                if (Control != null)
                {
                    Control.Source = imagesource;
                }

                RefreshImage();
            }
            else
            {
                Control.Source = null;
                Element?.SetIsLoading(false);
            }
        }
コード例 #7
0
 void IImageVisualElementRenderer.SetImage(Windows.UI.Xaml.Media.ImageSource image)
 {
     Control.Source = image;
 }