How to render bitmap into canvas in WPF?

前端 未结 3 637
日久生厌
日久生厌 2020-12-09 06:01

I\'ve subclassed Canvas so that I can override its Render function. I need to know how I can load a bitmap in WPF and render that to the canvas. I\

3条回答
  •  北海茫月
    2020-12-09 06:57

    This should get you started:

    class MyCanvas : Canvas {
       protected override void OnRender (DrawingContext dc) {
          BitmapImage img = new BitmapImage (new Uri ("c:\\demo.jpg"));
          dc.DrawImage (img, new Rect (0, 0, img.PixelWidth, img.PixelHeight));
       }
    }
    

提交回复
热议问题