Ejemplo n.º 1
0
        //Load bitmap from ImageBrush and set it as a bitmapDrawable background on target view
        private static async Task <IDisposable> SetImageBrushAsBackground(CancellationToken ct, BindableView view, ImageBrush background, Windows.Foundation.Rect drawArea, Path maskingPath, Action onImageSet)
        {
            var bitmap = await background.GetBitmap(ct, drawArea, maskingPath);

            onImageSet();

            if (ct.IsCancellationRequested || bitmap == null)
            {
                bitmap?.Recycle();
                bitmap?.Dispose();
                return(Disposable.Empty);
            }

            var bitmapDrawable = new BitmapDrawable(bitmap);

            SetDrawableAlpha(bitmapDrawable, (int)(background.Opacity * __opaqueAlpha));
            ExecuteWithNoRelayout(view, v => v.SetBackgroundDrawable(bitmapDrawable));

            return(Disposable.Create(() =>
            {
                bitmapDrawable?.Bitmap?.Recycle();
                bitmapDrawable?.Dispose();
            }));
        }