我正在将PDF页面转换为CanvasBitmap并在VirtualCanvasControl上绘制此图像。但每当我放大图片时,都会像素化一样。 我试图渲染只是可见的部分但似乎不起作用。我做错了什么?
<ScrollViewer Grid.RowSpan="2"
Grid.Row="0"
Name="PdfScrollViewer"
ZoomMode="Enabled"
MaxZoomFactor="4"
MinZoomFactor="0.8"
HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BringIntoViewOnFocusChange="False">
<canvas:CanvasVirtualControl x:Name="PageRenderCanvas" RegionsInvalidated="PageRenderCanvas_OnRegionsInvalidated"
/>
</ScrollViewer>
RegionsInvalidated EventHandler:
private async void PageRenderCanvas_OnRegionsInvalidated(CanvasVirtualControl sender,
CanvasRegionsInvalidatedEventArgs args)
{
PdfPageRenderOptions options = new PdfPageRenderOptions();
options.DestinationWidth = (uint) (PdfScrollViewer.ActualWidth*PdfScrollViewer.ZoomFactor);
options.DestinationHeight = (uint) (PdfScrollViewer.ActualHeight*PdfScrollViewer.ZoomFactor);
options.SourceRect = args.VisibleRegion;
var output = new MemoryStream().AsRandomAccessStream();
await page.RenderToStreamAsync(output, options); // page is the PDFPage
var image = await CanvasBitmap.LoadAsync(PageRenderCanvas, output);
using (var ds = sender.CreateDrawingSession(args.InvalidatedRegions[0]))
{
ds.DrawImage(image, args.VisibleRegion);
ds.Dispose();
}
}
答案 0 :(得分:0)
图像是像素化的,因为您正在渲染位图上执行缩放
由于没有关于VirtualCanvasControl和RegionsInvalidated事件的文档,我建议每次缩放更改时执行渲染,只在绘图事件中显示渲染图像。
但是,这种方法会在较大的缩放级别产生内存问题。考虑到96dpi为100%,字母页面将为816 * 1056像素,大约需要3MB。在500%变焦时,图像将为4080 * 5280像素,大约需要75MB。