RenderTargetBitmap doesn't seem to render my rectangle

后端 未结 1 1732
陌清茗
陌清茗 2021-01-20 14:30

I have the following code:

        LinearGradientBrush linGrBrush = new LinearGradientBrush();
        linGrBrush.StartPoint = new Point(0,0);
        linGrB         


        
相关标签:
1条回答
  • 2021-01-20 14:58

    Arrange has to be called after Measure, and the Rect values should be passed correctly.

    Instead of

    rect.Arrange(new Rect(0, 0, 1, 1000)); // wrong width and height
    rect.Measure(new Size(1000, 1));
    

    you should do

    var rect = new Rectangle { Fill = linGrBrush };
    var size = new Size(1000, 1);
    rect.Measure(size);
    rect.Arrange(new Rect(size));
    
    var bmp = new RenderTargetBitmap(1000, 1, 96, 96, PixelFormats.Pbgra32);
    bmp.Render(rect);
    
    0 讨论(0)
提交回复
热议问题