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