async void FfImage_Finish(object sender, CachedImageEvents.FinishEventArgs e) { ffImage.Finish -= FfImage_Finish; var asBytes = await ffImage.GetImageAsJpgAsync(90, 480, 480); var asStream = new MemoryStream(asBytes); exportedImage.Source = Xamarin.Forms.ImageSource.FromStream(() => asStream); asBytes = null; }
public StreamPage() { Title = "Stream with custom key test"; var cachedImage = new CachedImage() { HeightRequest = 300, WidthRequest = 300, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, }; var button = new Button() { Text = "Load again, but as stream", Command = new Command(async() => { var bytes = await cachedImage.GetImageAsJpgAsync(); cachedImage.Source = null; var streamSource = new StreamImageSource() { Stream = new Func <CancellationToken, Task <Stream> >((arg) => Task.FromResult <Stream>(new MemoryStream(bytes))) }; cachedImage.CacheKeyFactory = new CustomCacheKeyFactory(); cachedImage.Source = streamSource; }) }; Content = new StackLayout() { HorizontalOptions = LayoutOptions.FillAndExpand, Children = { cachedImage, button } }; // First we load an image from http source cachedImage.Source = "http://loremflickr.com/600/600/nature?filename=stream.jpg"; }
public GetImageTestPage() { Title = "GetImage Test Page"; var img = new CachedImage { Source = "http://i.imgur.com/6ZUYWDE.jpg", LoadingPlaceholder = "placeholder.jpg", }; _copiedImageJpg = new CachedImage { LoadingPlaceholder = "placeholder.jpg" }; _copiedImagePng = new CachedImage { LoadingPlaceholder = "placeholder.jpg" }; img.Finish += OnFinish; _copyJPG = new Button() { Text = "Copy as JPG", IsEnabled = false }; _copyPNG = new Button() { Text = "Copy as PNG", IsEnabled = false }; _copyJPG.Clicked += async(s, e) => { var data = await img.GetImageAsJpgAsync(); _copiedImageJpg.Source = ImageSource.FromStream(() => { return(new MemoryStream(data)); }); }; _copyPNG.Clicked += async(s, e) => { var data = await img.GetImageAsPngAsync(); _copiedImagePng.Source = ImageSource.FromStream(() => { return(new MemoryStream(data)); }); }; Content = new ScrollView { Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { img, _copyJPG, _copyPNG, _copiedImageJpg, _copiedImagePng } } }; }