簡體   English   中英

圖像質量模糊

[英]image quality is blurry

我遇到一種情況,我想將一些XAML轉換為圖像,所以我創建了RichTextBox,然后獲取了它的圖像。 現在的問題是圖像中的文字模糊不清,我怎么能解決這個問題?

public System.Drawing.Bitmap ConvertXamltoImage(string XamlString, int Width, int Height)
{

    RichTextBox AdContentRichTextBox = new RichTextBox() { Width = Width, Height = Height };
    AdContentRichTextBox.BorderThickness = new Thickness(0);
    XmlReader _XmlReader = XmlReader.Create(new StringReader(XamlString));

    AdContentRichTextBox.Document = XamlString;          

    var size = new Size(Width, Height);
    AdContentRichTextBox.Measure(size);
    AdContentRichTextBox.Arrange(new Rect(size));
    RenderTargetBitmap bmp = new RenderTargetBitmap(Width, Height, 300, 300, PixelFormats.Pbgra32);

    bmp.Render(AdContentRichTextBox);


    DrawingVisual _drawingVisual = new DrawingVisual();

    using (DrawingContext _drwaingContext = _drawingVisual.RenderOpen())
    {
        VisualBrush _visualBrush = new VisualBrush(AdContentRichTextBox);
    }

    PngBitmapEncoder _png = new PngBitmapEncoder();

    _png.Frames.Add(BitmapFrame.Create(bmp));
    System.Drawing.Bitmap _tempBitmap = null;
    using (Stream _fileStream = new MemoryStream())
    {
        _png.Save(_fileStream);
        _tempBitmap = new System.Drawing.Bitmap(_fileStream);

        _fileStream.Flush();
    }
    return _tempBitmap;
}

嗯..可能有很多東西在這里相互作用:

第一

“灰度回退-如果在無法運行ClearType算法的某些情況下禁用了ClearType或正在渲染文本,則WPF將使用灰度渲染算法對所渲染的文本進行反鋸齒。”

將文本渲染到RenderTargetBitmap似乎是其中一種情況。...(渲染器從硬件路徑切換到軟件路徑)。

第二名

此外,NET 4將默認縮放算法從高品質(Fant)切換為低品質(Bi-Linear).....現在不應該在這里發揮作用,因為它看起來像您在縮放位圖以任何方式...但是您永遠不知道內部發生了什么。 可以將潔牙機切換回更高質量的潔牙機。

第三名

您可能需要考慮RichTextBox的父容器...請參閱下面的最后一個鏈接,提及它會扭曲字體渲染。


有關如何解決此問題的一些想法是:

  1. 以更高的分辨率(例如600dpi)呈現RichTextBox,然后按比例縮小位圖(可能不會有任何區別)

  2. 捕獲屏幕...。如果視覺不清晰/模糊等,則很難或不切實際。


查看相關鏈接:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM