我正在向屏幕外CanvasRenderTarget
画画。然后我将其绘制到我的CanvasAnimatedControl
。
复制的位图是模糊的&#39 ;;第一行是屏幕外位图,第二行是直接绘制到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>
出了什么问题?
更新我想出来了,但认为这可能是一个有用的参考问题
答案 0 :(得分:0)
我在写这个问题和blogged about it时想出了答案。
基本上,我的问题是我只是缩放主绘图会话而不是屏幕外会话。新代码是:
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);
}
产生: