Forum Libraries, Components, and Plugins

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

Answers

  • McC1oudMcC1oud Member ✭✭
    edited January 9

    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: "ZorduGamma.GameImages.me.jpg" ?

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

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

    Can't find the file.

  • McC1oudMcC1oud Member ✭✭
    edited January 9

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

    string resourceID = "ZorduGamma.GameImages.me.jpg";
    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.