WPF RenderTargetBitmap将文本RenderMode缩小到灰度
RenderTargetBitmap删除将RichtextBox的TextRenderingMode降级为灰度。因此,捕获的PNG看起来质量很差,与WPF控件不匹配 如果我使用WINDOWS ALT+PRINT屏幕,文本将被完美捕获 那么,如何将文本控件渲染为与ALT+PRINT屏幕相同的质量呢 如有任何建议,将不胜感激WPF RenderTargetBitmap将文本RenderMode缩小到灰度,wpf,rendertargetbitmap,Wpf,Rendertargetbitmap,RenderTargetBitmap删除将RichtextBox的TextRenderingMode降级为灰度。因此,捕获的PNG看起来质量很差,与WPF控件不匹配 如果我使用WINDOWS ALT+PRINT屏幕,文本将被完美捕获 那么,如何将文本控件渲染为与ALT+PRINT屏幕相同的质量呢 如有任何建议,将不胜感激 最好的您可以使用与windows在使用Alt+Print screen拍摄屏幕快照时使用的相同技术将窗口渲染到位图中。其思想是获取一个窗口句柄,然后使用系统调用将其渲染为位图
最好的您可以使用与windows在使用Alt+Print screen拍摄屏幕快照时使用的相同技术将窗口渲染到位图中。其思想是获取一个窗口句柄,然后使用系统调用将其渲染为位图 下面是一个示例(您需要在项目中引用System.Drawing.dll程序集才能使其正常工作): 你可以这样称呼它
private void saveButton_Click(object sender, RoutedEventArgs e)
{
// saves the entire window into the bitmap
SaveToBitmapNative(this, this, "c:\\test0.png");
// saves a child control (RichTextBox) into the bitmap
SaveToBitmapNative(this, richTextBox, "c:\\test1.png");
}
注意:这不适用于通过函数更新的分层窗口
希望这能有所帮助,尊敬你好,Serge,谢谢你的回答,但是(我没有正确解释),我需要在richtextbox中捕获文本,其背景是透明的,而不是作为屏幕的一部分。Rendertargetbitmap复制控件并捕获png,因此它后面的内容不在位图中。
private void saveButton_Click(object sender, RoutedEventArgs e)
{
// saves the entire window into the bitmap
SaveToBitmapNative(this, this, "c:\\test0.png");
// saves a child control (RichTextBox) into the bitmap
SaveToBitmapNative(this, richTextBox, "c:\\test1.png");
}