我正在尝试从Silverlight 4应用程序打印图像(QR码),但是打印时图像是防污的(我已经尝试了XPS文件打印机和硬件打印机)图像是blury,并且条形码阅读器无法读取.
来自印刷的XPS文件的图片http://img805.imageshack.us/img805/7677/qraliasing.png
我正在使用这个简单的代码来打印它:
WriteableBitmap bitmap = new WriteableBitmap(width, height);
//write bitmap pixels
Image image = new Image(){Stretch = Stretch.None};
image.Source = bitmap;
image.Width = bitmap.PixelWidth;
image.Height = bitmap.PixelHeight;
//Print
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += (sender, args) =>
{
args.PageVisual = image;
};
printDocument.Print("QrCode");
Run Code Online (Sandbox Code Playgroud)
我找到了解决办法。
在 Silverlight 4 中打印图像控件时,它发送到打印机的不是图像控件的“打印屏幕”(如在 UserControl 中所示),而是在其源属性中设置的图像。如果生成两个 100x100 像素和 1000x1000 像素分辨率的位图并将它们放入 100x100 像素大小的图像控件中,打印结果将与您预期的不同。
因此,解决方案是生成高分辨率图像(或高档图像)并将其放入所需大小的图像控件中。