tags:

views:

3239

answers:

4

I'm looking for an example of how to load an image from file and print it on a page using WPF. I'm having a hard time finding good information about WPF printing.

A: 

Just load the image and apply it to a visual. Then use the PrintDialog to do the work.

...
PrintDialog printer = new PrintDialog();

if (printer.ShowDialog()) {
  printer.PrintVisual(myVisual, "A Page Title");
}
MojoFilter
+9  A: 
var bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = new Uri("");
bi.EndInit();

var vis = new DrawingVisual();
var dc = vis.RenderOpen();
dc.DrawImage(bi, new Rect { Width = bi.Width, Height = bi.Height });
dc.Close();

var pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true) {
 pdialog.PrintVisual(vis, "My Image");
}
Tamir
A: 

If you want more control then PrintDialog.PrintVisual gives you you have to wrap your image in a FixedDocumet.

You can find simple code that creates a fixed document here: http://www.ericsink.com/wpf3d/B_Printing.html

Nir
A: 

How to print image with watermark? Thanks in advance

Raju davis

Raju davis
You should better ask this as a new question, more people would look at it and try to help you. (And it's not an answer to this question, so not very helpful here in that respect.) Also make sure to include enough details in your question.
sth