Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF RenderTargetBitmap将文本RenderMode缩小到灰度_Wpf_Rendertargetbitmap - Fatal编程技术网

WPF RenderTargetBitmap将文本RenderMode缩小到灰度

WPF RenderTargetBitmap将文本RenderMode缩小到灰度,wpf,rendertargetbitmap,Wpf,Rendertargetbitmap,RenderTargetBitmap删除将RichtextBox的TextRenderingMode降级为灰度。因此,捕获的PNG看起来质量很差,与WPF控件不匹配 如果我使用WINDOWS ALT+PRINT屏幕,文本将被完美捕获 那么,如何将文本控件渲染为与ALT+PRINT屏幕相同的质量呢 如有任何建议,将不胜感激 最好的您可以使用与windows在使用Alt+Print screen拍摄屏幕快照时使用的相同技术将窗口渲染到位图中。其思想是获取一个窗口句柄,然后使用系统调用将其渲染为位图

RenderTargetBitmap删除将RichtextBox的TextRenderingMode降级为灰度。因此,捕获的PNG看起来质量很差,与WPF控件不匹配

如果我使用WINDOWS ALT+PRINT屏幕,文本将被完美捕获

那么,如何将文本控件渲染为与ALT+PRINT屏幕相同的质量呢

如有任何建议,将不胜感激


最好的

您可以使用与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"); 
}