0

我正在画到屏幕外CanvasRenderTarget。然后我把它画到我的CanvasAnimatedControl.

复制的位图“模糊”;第一行是离屏位图,第二行是直接绘制到会话CanvasAnimatedControl

模糊

它不是太明显,但在应用缩放时更加明显:

在此处输入图像描述

这是代码:

public sealed partial class MainPage
{
    const string Text = "WHY AM I BLURRY!? MMmm///AaBbCcDdEeFf!!££$$%%ZZAA";

    Matrix3x2 _scale = Matrix3x2.CreateScale(3,3);
    
    CanvasRenderTarget _offscreenCanvas;

    readonly CanvasTextFormat _ctf = new CanvasTextFormat
    {
        FontFamily = "Century Gothic",
        FontSize = 20
    };


    public MainPage() => InitializeComponent();

    void onCanvasDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
    {
        args.DrawingSession.Transform = _scale;

        args.DrawingSession.Clear(Colors.Aquamarine);

        using (var offscreenSession = _offscreenCanvas.CreateDrawingSession())
        {
            offscreenSession.Clear(Colors.Aquamarine);

            offscreenSession.DrawText(Text, 0, 0, Colors.Red, _ctf);
            offscreenSession.DrawLine(new Vector2(0,0), new Vector2(100,10), Colors.Black);
        }

        //args.DrawingSession.DrawImage(_offscreenCanvas, Vector2.Zero, _offscreenCanvas.Bounds, 1f, CanvasImageInterpolation.Linear);
        args.DrawingSession.DrawImage(_offscreenCanvas,0,0);

        args.DrawingSession.DrawText(Text, 0, 20, Colors.Red, _ctf);
        args.DrawingSession.DrawLine(new Vector2(0, 20), new Vector2(100, 30), Colors.Black);

    }

    void onCanvasCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args) => 
        _offscreenCanvas = new CanvasRenderTarget(sender.Device, 800, 20, 96);
}

这是 XAML:

<Grid Background="Black">
    <xaml:CanvasAnimatedControl Draw="onCanvasDraw" CreateResources="onCanvasCreateResources" BorderThickness="5" BorderBrush="Blue"/>
</Grid>

怎么了?

更新 我想通了,但认为这可能是一个有用的参考问题

4

1 回答 1

1

我在写这个问题时想出了答案并写了博客

基本上,我的问题是我只缩放主绘图会话而不是屏幕外会话。新代码是:

    void onCanvasDraw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
    {
        args.DrawingSession.Clear(Colors.Aquamarine);

        using (var offscreenSession = _offscreenCanvas.CreateDrawingSession())
        {
            offscreenSession.Transform = _scale;

            offscreenSession.Clear(Colors.Aquamarine);

            offscreenSession.DrawText(Text, 0, 0, Colors.Red, _ctf);
            offscreenSession.DrawLine(new Vector2(0,0), new Vector2(100,10), Colors.Black);
        }

        args.DrawingSession.DrawImage(_offscreenCanvas, 0,0);

        args.DrawingSession.Transform = _scale;

        args.DrawingSession.DrawText(Text, 0, 20, Colors.Red, _ctf);
        args.DrawingSession.DrawLine(new Vector2(0, 20), new Vector2(100, 30), Colors.Black);

}

产生:

在此处输入图像描述

于 2018-01-11T13:01:02.480 回答