0
我正在尝试为PDF文件实现日/夜模式;渲染后。 这样做的最佳解决方案是什么?可以通过在Windows应用商店中使用主题完成吗?如何在Windows应用商店中为PDF文件实施日/夜?
我正在尝试为PDF文件实现日/夜模式;渲染后。 这样做的最佳解决方案是什么?可以通过在Windows应用商店中使用主题完成吗?如何在Windows应用商店中为PDF文件实施日/夜?
Venkata也posted on the MSDN forums,他在那里澄清,他使用PdfDocument API,并希望反转白色的黑色和黑色的白色。如果你这样做,一定要考虑高对比度模式(我只是在高对比度模式下跳过你的反演,因为用户已经在管理它)。
您可以在您传递给RenderToStreamAsync(或者,如果你使用IPdfRendererNative和RenderPageToSurface的PDF_RENDER_PARAMS的PdfPageRenderOptions页面背景,但没有办法覆盖的前景在这一水平。
一旦例如,您可以将它加载到一个WriteableBitmap中,然后循环遍历像素并反转颜色:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///assets/demo.pdf"));
PdfDocument pdfDoc = await PdfDocument.LoadFromFileAsync(file);
PdfPage pdfPage = pdfDoc.GetPage(0);
using (IRandomAccessStream stream = new InMemoryRandomAccessStream())
{
PdfPageRenderOptions options = new PdfPageRenderOptions();
await pdfPage.RenderToStreamAsync(stream, options);
WriteableBitmap wb = new WriteableBitmap((int)pdfPage.Size.Height, (int)pdfPage.Size.Width);
await wb.SetSourceAsync(stream);
using (Stream pixels = wb.PixelBuffer.AsStream())
{
pixels.Seek(0, SeekOrigin.Begin);
for (int i = 0; i < pixels.Length; i++)
{
byte subPixel = (byte)pixels.ReadByte();
// WB pixels are RGBA. Only change RGB, not A
if ((i + 1) % 4 != 0)
{
// write over the same pixel we just read
pixels.Seek(-1, SeekOrigin.Current);
// write the modified pixel (inverted colour in this case)
pixels.WriteByte((byte)(byte.MaxValue - subPixel));
}
}
}
// Display the page on an Image in our Xaml Visual Tree
img.Source = wb;
}
你在用什么来修改它的像素?创建PDF文件? – 2014-09-23 10:50:35