I am trying to print an image (QR code) from a Silverlight 4 application, but when printing (for example, I tried both a file with XPS files and a hardware printer), the image becomes blurry and cannot be read by a barcode reader.
Image from a printed XPS document http://img805.imageshack.us/img805/7677/qraliasing.png
I use this simple code to print it:
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");
I have found a solution.
Silverlight 4 " " , UserControl, , . 100x100 1000x1000 100x100px. , .
, ( ) .
, , , ...
, PrintDocument UIElement ( ), 96 DPI, 600 DPI, . , , , , - .
, blit , RenderTransform, PrintDocument , blit.
RenderTransform
QR- ( 600/96 = 6,25 ), , :
image.RenderTransform = new ScaleTransform { ScaleX = 96.0 / 600.0, ScaleY = 96.0 / 600.0 };
, .
?
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) => { //**Add this** args.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; args.PageVisual = image; }; printDocument.Print("QrCode");