private static global::Android.Graphics.Bitmap GetBitmap(AdaptiveBlockImage img) { var result = GetBitmapAsync(img); result.Wait(); if (result.Exception != null) { throw result.Exception; } return(result.Result); }
public bool ConsumeImage(Func <AdaptiveBlockImage, bool> predicate, out AdaptiveBlockImage image) { if (Content.Images != null) { image = Content.Images.FirstOrDefault(predicate); if (image != null) { Content.Images.Remove(image); return(true); } } image = null; return(false); }
internal bool Matches(AdaptiveBlockImage image) { if (RequiredHint.Count > 0) { if (!RequiredHint.Any(required => image.Hints.Category.Contains(required))) { return(false); } } if (HintsToAvoid.Any(avoid => image.Hints.Category.Contains(avoid))) { return(false); } return(true); }
private static async Task <global::Android.Graphics.Bitmap> GetBitmapAsync(AdaptiveBlockImage img) { try { if (img == null) { return(null); } using (HttpClient client = new HttpClient()) { var stream = await client.GetStreamAsync(img.Url); return(await BitmapFactory.DecodeStreamAsync(stream)); } } catch { return(null); } }
private static bool PlaceImageMatch(ImageMatchRequest[] requests, AdaptiveBlockImage img, IEnumerable <ImageMatchRequest> alreadySwapped) { List <ImageMatchRequest> swappables = new List <ImageMatchRequest>(); for (int i = 0; i < requests.Length; i++) { var req = requests[i]; if (req.Matches(img)) { if (req.ImageResult == null) { req.ImageResult = img; return(true); } else if (!alreadySwapped.Contains(req)) { swappables.Add(req); } } } foreach (var swappable in swappables) { var swappingImg = swappable.ImageResult; swappable.ImageResult = img; if (PlaceImageMatch(requests, swappingImg, alreadySwapped.Concat(new ImageMatchRequest[] { swappable }))) { return(true); } swappable.ImageResult = swappingImg; } return(false); }
public bool ConsumeImage(AdaptiveBlockImageCategoryHints category, out AdaptiveBlockImage image) { return(ConsumeImage(i => i.Hints.Category.Contains(category), out image)); }
private bool ConsumeImage(AdaptiveBlockImageCategoryHints preferredCategory, List <AdaptiveBlockImageCategoryHints> categoriesToAvoid, out AdaptiveBlockImage image) { return(ConsumeImage(i => i.Hints.Category.Contains(preferredCategory) && i.Hints.Category.All(c => !categoriesToAvoid.Contains(c)), out image)); }
public AdaptiveBlockImageConsumer(AdaptiveBlockImage image, AdaptiveBlockConsumerProperties properties) { Image = image; Properties = properties; }
public static ImageSource CreateImageSource(this AdaptiveBlockImage img) { return(new BitmapImage(new Uri(img.Url))); }