WPF Screenshot JPG from UIElement with C#

霸气de小男生 提交于 2019-12-03 03:50:29

Just a guess, I would think that a black background would represent portions of the byte array that are not set to anything in this process. The initial zeros in the array would appear as black.

To avoid this, I suggest initializing the array with 0xFF (byte.MaxValue) values.

UPDATED:

From looking at this closer, I think you should draw a white rectangle onto the image before you render the UI element. That ought to work anyway.

Just before this line of code

drawingContext.DrawRectangle(sourceBrush, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight))); 

put something like this

drawingContext.DrawRectangle(Brushes.White, null, new Rect(new Point(0, 0), new Point(actualWidth, actualHeight))); 

Unfortunately the only thing that worked was just setting the element's background in the XAML. I didn't want to do this, but I guess it is what I need to do in this case. Thanks anyway for the suggestion.

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