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."); }
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)); }
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; }
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; }
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)); }
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); } }
void IImageVisualElementRenderer.SetImage(Windows.UI.Xaml.Media.ImageSource image) { Control.Source = image; }