Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Load an image from the device into skiasharp canvas view?

What I want to do is either:

  • load a picture from (i.e: gallery) into the canvas and draw on top of it, or
  • do some drawing on a canvas then combine it with a picture

Or if there is other way to achieve this?

Best Answers


  • McC1oudMcC1oud Member ✭✭
    edited January 2020

    In that example, what is: "SampleMedia.Images.BabyTux"

    I'm trying to figure out where to be loading my files from.
    My solution folder is: "ZorduGamma"
    I created a folder at the top called: GameImages
    The file is called: "me.jpg"

    Should the file directory be: "" ?

    This is what I am attempting to use to load an image into SkiaSharp:

    public static FileStream streamBG = new FileStream("", FileMode.Open);
    public static SKBitmap bgBit = SKBitmap.Decode(streamBG);
    SKImage backGroundDecode = SKImage.FromBitmap(bgBit);

    Can't find the file.

  • McC1oudMcC1oud Member ✭✭
    edited January 2020

    Ok, I got it. I'm using this chunk to load the image successfully:

    string resourceID = "";
    Assembly assembly = typeof(GamePlay).GetTypeInfo().Assembly;
    var resource = assembly.GetManifestResourceStream(resourceID);
    var stream = new SKManagedStream(resource);
    SKBitmap bgBit = SKBitmap.Decode(stream);
    backGroundDecode = SKImage.FromBitmap(bgBit);

    I am unsure about the assembly and was not sure what to put in the typeof so I just put the class in it. Is this correct? I got lucky with a guess.

  • MondonnoMondonno Member ✭✭

    @McC1oud What is the GamePlay in Assembly assembly = typeof(GamePlay).GetTypeInfo().Assembly; ?
    It is project name? Or class name?

Sign In or Register to comment.