如何在 WPF 中将位图渲染到画布中? [英] How to render bitmap into canvas in WPF?
本文介绍了如何在 WPF 中将位图渲染到画布中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经继承了 Canvas
以便我可以覆盖它的 Render
函数.我需要知道如何在 WPF 中加载位图并将其渲染到画布上.我是 WPF 的新手,我还没有找到任何教程可以向您展示如何做一些看似微不足道的事情.带有示例的分步说明会很棒.
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'm completely new to WPF and I haven't found any tutorials that show you how to do something so seemingly trivial. Step-by-step instructions with examples would be great.
推荐答案
这应该会让你开始:
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));
}
}
这篇关于如何在 WPF 中将位图渲染到画布中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文