WPF Polygon to bitmap

假如想象 提交于 2019-12-24 12:27:59

问题


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;

回答1:


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.




回答2:


use

(int)image1.ActualWidth 

and

(int)image1.ActualHeight


来源:https://stackoverflow.com/questions/3509296/wpf-polygon-to-bitmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!