c# wpf polygon to bitmap not displaying anything

前端 未结 1 565
猫巷女王i
猫巷女王i 2020-12-22 12:44

Sorry if you think this question was already answered, I did look everywhere trying to find out how come when I do this, it is not displaying anything. This is all my code:<

相关标签:
1条回答
  • 2020-12-22 13:04

    A WPF UIElement has to be laid out before being visible. It has to get at least one Measure and Arrange call, where it gets an available Size and a final arrange Rect (usually from its parent Panel). When rendering a newly created element into a RenderTargetBitmap, you would call these methods manually, with appropriate values for the Size and Rect:

    ...
    hexagon.Measure(new Size(200, 200)); // adjust this to your needs
    hexagon.Arrange(new Rect(0, 0, 200, 200)); // adjust this to your needs
    
    var bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Default);
    bmp.Render(hexagon);
    
    0 讨论(0)
提交回复
热议问题