WPF 多边形到位图

发布于 2024-09-14 19:20:21 字数 315 浏览 2 评论 0原文

如何将 wpf 多边形形状转换为位图图像?我正在尝试作为视觉参数发送以更改为位图,但它似乎不起作用。还有其他方法可以将 WPF 多边形转换为位图吗?

我正在使用如下所示

RenderTargetBitmap RTbmap = new RenderTargetBitmap((int)yellowPolygon.Width, (int)yellowPolygon.Height, 96, 96, PixelFormats.Default);
RTbmap.Render(yellowPolygon); 
image1.Source = RTbmap;

How can I convert the wpf polygon shape as a bitmap image? I am trying to send as Visual parameter to change as bitmap, but it doesn't seem to be working. Is there any other way to convert the WPF polygon to bitmap?

am using like below

RenderTargetBitmap RTbmap = new RenderTargetBitmap((int)yellowPolygon.Width, (int)yellowPolygon.Height, 96, 96, PixelFormats.Default);
RTbmap.Render(yellowPolygon); 
image1.Source = RTbmap;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-09-21 19:20:21

宽度高度更改为ActualWidthActualHeight

通过点定义的线、多边形等具有未定义的宽度和高度。渲染位图时,您应该使用 ActualWidthActualHeight

我刚刚在一个示例项目中尝试过这个,它工作得很好。

Change Width and Height to ActualWidth and ActualHeight.

Line, polygon etc which are defined via points have undefined width and height. When rendering to a bitmap you should use ActualWidth and ActualHeight.

I just tried this in a sample project and it works just fine.

宫墨修音 2024-09-21 19:20:21

使用

(int)image1.ActualWidth 

(int)image1.ActualHeight

use

(int)image1.ActualWidth 

and

(int)image1.ActualHeight
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文