Silverlight 5 print fail with high DPI - silverlight

I'm using Silverlight 5 and PrintDocument in order to print document (with one bitmap image and several TextBox).
If I try to create a PDF (for example with CutePDF) A4 with 600 DPI, everything is ok, the PDF file is generated.
But if i try to create A1 with 600 DPI, nothing happens, print job is not created as well as the PDF file. If I try A1 with 72 or 144 DPI, then it works.
What could be a problem? Silverlight has some limit?
Thanks in advance.

Related

My WPF icons are displayed very small

My WPF icons are displayed very small, as you can see in this image, can you please
suggest what could be the problem? I tried to find some properties related to size but
no success.
One problem could be the bitmap's resolution. Open the bitmap for example in Paint.NET and in the Resize Bitmap dialog check whether it is 72DPI or 96DPI. A large ribbon bitmap should be 32x32 Pixels at 96 DPI.
By the way, in your screenshot the bitmaps actually look ok. What makes you think they are too small?
WPF uses an unusual resolution of 96 dpi... I'm guessing that your images have not been saved at this resolution.

How to rotate a bitmap by 90 degrees and get a valid metafile

I am using PlgBlt to rotate a Windows bitmap over 90 degrees. This works fine when displaying the map on screen, but inspecting an enhanced metafile made of this process shows the rotated bitmap completely missing.
Rotated text (with CreateFontIndirect()), output through TextOut(), is also missing from the enhanced metafile. A simple bitmap rotation/flip routine combined with StretchBlt() works fine.
PlgBlt is using a device-dependent bitmap, while an enhanced metafile is supposed to be device-independent. Could that be it?

Printing with more than 96 dpi in WPF

Let me explain the problem, I'm getting stuck in it
If I change the dpi settings from the dialog of Printing Preferences of a virtual printer like PDF Creator or any printer that allows to change this setting, and then set a breakpoint like the code below:
PrintDialog printDialog = new PrintDialog();
if ((bool)printDialog.ShowDialog().GetValueOrDefault())
{
System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
...... insert breakpoint here
}
I can see that the properties printDialog.PrintTicket.PageResolution.X; and printDialog.PrintTicket.PageResolution.Y change correctly while printDialog.PrintTicket.PageMediaSize.Width and printDialog.PrintTicket.PageMediaSize.Height don't change despite the printer resolution change... an A4 paper in portrait mode will always have PageMediaSize.Height = 1122.5196850393702 and PageMediaSize.Width = 793.70078740157476 no matter which resolution is set before ..... for WPF the unit size of these dimensions is set to 1/96th inch but when is Ok on screen because default screen resolution is 96 dpi on the other side is wrong on the printer because it has a different resolution, in other words confuting that Height and Width of the paper are read only properties if I cannot find the way to tell WPF that the unit size of the printer is not 1/96th inch but for example 1/300th inch (if on the printer I previously set 300 dpi ) there's absolutely no way to print at higher resolution than 96dpi
A last note, in my specific case I cannot use RenderTargetBitmap and then resize all to match printer's paper height and width settings because I'm printing high definition barcode images and it would cause an image rescaling that would make the barcode unreadable on final paper because i create it with the purpose to be printed with a resolution of 300dpi which without a resizing will result out of bounds because WPF is telling me the printer paper dimensions in the wrong unit size (1/96th inch) despite the real dpis prevoiusly set on printer
Hoping to have clarified enough the problem,
thanks in advance,
Dave

Silverlight printing size is too large

I've developed application using Silverlight, and now I need to implement printing, I've used
PrintDocument class, it looks like this:
PrintDocument printDocument = new PrintDocument();
printDocument.PrintPage += new EventHandler<PrintPageEventArgs>(printDocument_PrintPage);
printDocument.Print("My docuement");
But I've faced with problem - it takes much time if there are 20-30 pages, and if I open printer's queue, it shows that printing size is about 1.2GB for 10 printed pages. I've tried to print canvas (800*1000) with only one textblock with simple text like "Test printing".
I'm using Silverlight 5.
Did anybody faced with such problem? Is there any way to avoid it?
My guess is that the content to be printed is send as a bitmap instead of a more efficient vector format.
This might be due to the driver. If the driver of the printer is not able to translate the Silverlight graphics into vectors, all it can do is print it as a bitmap.
I tried to force Silverlight into using Vectors but my printer didn't support PostScript.
So I switched to a printer that does and suddenly it's just kilobytes.
I see only two ways to avoid bitmap printing:
Get a PostScript printer or
Create a printer friendly document (PDF, Word, text) on the server and allow the client to download and print it by hand.

WPF 3D video memory efficiency

Ill try to explain my situation as best as I can, sorry if it is not too clear...
I have a Viewport3D that contains some large 3d rectangles that are like big crystals.
When the user click on one of the crystals, I add a new material to the crystal in the spot the use clicked using an ImageBrush. I then iterate over a list of bitmaps (List<BitmapImage> collection) and update the ImageBrush each frame to create an animation on the 3D crystal.
This works nice and I have up to 5 different effects playing on the crystals, but after profiling my application, I have discovered that due to mipmaps (I think) and the way 3d renders, my video memory jumps through the roof!!
By my calculation, if I have a 75 frame animation, by 400x400 running at 4 bytes per pixel, and having ~5 different animations piled up, you can see how this can get large :)
75 * 400 * 400 * 4 * 5 = ~250MB
this is an issue, not only because of the size, but also, the BitmapImages stay in Video Memory until I make them null, which is very annoying and performance costly.
My idea to fix this is to change from having List<BitmapImage> collection, to having a List<Byte[]> and rather than updating an ImageSource, I would like to try to use a WriteableBitmap that write the bytes to it.
The issue is I have no idea how to read bytes from a PNG file, then create a WriteableBitmap and write the bytes to it over and over in an efficient manor.
Can anyone please help me out?
WriteableBitmap is actually pretty bad with performance, even though it takes dirty regions. Try using the InteropBitmap. I have an class ready to go for it here:
http://silverlightviewport.codeplex.com/SourceControl/changeset/view/33100#809062

Resources