Ejemplo n.º 1
0
        public override Task <IImageSourceServiceResult <Drawable>?> GetDrawableAsync(IImageSource imageSource, Context context, CancellationToken cancellationToken = default)
        {
            var bitmap = imageSource switch
            {
                ISKImageImageSource img => img.Image?.ToBitmap(),
                ISKBitmapImageSource bmp => bmp.Bitmap?.ToBitmap(),
                ISKPixmapImageSource pix => pix.Pixmap?.ToBitmap(),
                ISKPictureImageSource pic => pic.Picture?.ToBitmap(pic.Dimensions),
                _ => null,
            };

            return(bitmap != null
                                ? FromResult(new ImageSourceServiceResult(new BitmapDrawable(context.Resources, bitmap), () => bitmap.Dispose()))
                                : FromResult(null));
        }
        public override Task <IImageSourceServiceResult <UIImage>?> GetImageAsync(IImageSource imageSource, float scale = 1, CancellationToken cancellationToken = default)
        {
            var image = imageSource switch
            {
                ISKImageImageSource img => img.Image?.ToUIImage(),
                ISKBitmapImageSource bmp => bmp.Bitmap?.ToUIImage(),
                ISKPixmapImageSource pix => pix.Pixmap?.ToUIImage(),
                ISKPictureImageSource pic => pic.Picture?.ToUIImage(pic.Dimensions),
                _ => null,
            };

            return(image != null
                                ? FromResult(new ImageSourceServiceResult(image, () => image.Dispose()))
                                : FromResult(null));
        }
Ejemplo n.º 3
0
        public override Task <IImageSourceServiceResult <WImageSource>?> GetImageSourceAsync(IImageSource imageSource, float scale = 1, CancellationToken cancellationToken = default)
        {
            var bitmap = imageSource switch
            {
                ISKImageImageSource img => img.Image?.ToWriteableBitmap(),
                ISKBitmapImageSource bmp => bmp.Bitmap?.ToWriteableBitmap(),
                ISKPixmapImageSource pix => pix.Pixmap?.ToWriteableBitmap(),
                ISKPictureImageSource pic => pic.Picture?.ToWriteableBitmap(pic.Dimensions),
                _ => null,
            };

            return(bitmap != null
                                ? FromResult(new ImageSourceServiceResult(bitmap))
                                : FromResult(null));
        }