ImageSource to UIImage

How can I set the source of a UIImage to an ImageSource?

Posts

  • I think it is not possibel, you can use a byte[] or Splat

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Try this:

    private Task<UIImage> GetImageFromImageSource(ImageSource imageSource)
    {
        IImageSourceHandler handler = null;
    
        if (imageSource is FileImageSource)
        {
            handler = new FileImageSourceHandler();
        }
        else if (imageSource is StreamImageSource)
        {
            handler = new StreamImagesourceHandler(); // sic
        }
        else if (imageSource is UriImageSource)
        {
            handler = new ImageLoaderSourceHandler(); // sic
        }
        else
        {
            throw new NotImplementedException();
        }
    
        return handler.LoadImageAsync(imageSource);
    }
    

    Internally Xamarin.Forms has a mechanism for registering these handlers with the different types of ImageSource subclasses, but that registration system seems to be internal. The actual handlers and the interface, though, are not internal, and I think you can use them safely.

  • AsfendYarAsfendYar USMember ✭✭

    How to Implement that code in Xamarin Android ?

  • adamkempadamkemp USInsider, Developer Group Leader mod
    edited October 2016

    I have an example of the Android equivalent here.

    EDIT: Make sure you remove this line, which is for the custom renderer I was building:

    var blurredBitmap = await Task.Run(() => CreateBlurredImage(originalBitmap, 25));
    

    Just return originalBitmap instead.

Sign In or Register to comment.