Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight printing anti-aliasing

Tags:

c#

silverlight

I'm trying to print an image (QR code) from Silverlight 4 app, however the image is antialised when printed (I have tried both XPS file printer and hardware printer)image is blury, and is not readable by barcode reader.

Image from printed XPS document http://img805.imageshack.us/img805/7677/qraliasing.png

I'm using 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");
like image 358
Alex Burtsev Avatar asked Nov 13 '22 15:11

Alex Burtsev


1 Answers

I have found a solution.

When printing Image control in Silverlight 4, it sends to printer not a "print screen" of an image control like it looks in your UserControl but an image set in it's source property. If you generate two bitmaps of 100x100 px and 1000x1000px resolutions and put them in 100x100px size Image controls the print result will not be the same as you may expect.

So the solution is to generate high resolution image (or upscale image) and put it in Image controls of desired size.

like image 111
Alex Burtsev Avatar answered Nov 23 '22 23:11

Alex Burtsev