Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Ioad an Image from a file and draw it on a WPF Skiasharp canvas?

Tags:

wpf

skiasharp

SkiaSharp WPF <- Important

enter image description here

I want to display the Compass.png image at a certain location on my SkiaSharp canvas. I am already drawing lines and circles on the canvas, I do NOT need help with that.

private void MyCanvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
  var surface = e.Surface;
  var canvas = surface.Canvas;
    
  canvas.Clear(SKColors.Black);
    
  // ... working drawing code drawing lines/circles already here
    
  // ** Need to add code here to load the compass image from the file and display it on the canvas at say (0, 0)?
}

Note: WPF.

like image 787
Rob L Avatar asked Dec 01 '25 06:12

Rob L


1 Answers

Worked it out...

var image = SKImage.FromEncodedData(@"Images\Compass.png");
var bm = SKBitmap.FromImage(image);

canvas.DrawBitmap(bm, new SKPoint(0, 0));

Obviously, better to just set the bm one time and reuse it.

like image 63
Rob L Avatar answered Dec 03 '25 22:12

Rob L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!