2011-03-15 124 views
1

我有以下C#代码打印8x6照片在桌面应用程序。照片打印在C#

它的工作原理与普通信纸尺寸的纸张普通打印机上。
但我的客户端使用柯达打印机与8x6纸,照片打印,但它们的大小是不同的,他们没有完全8x6尺寸打印,我做错了什么。

是否有人可以指导我在正确的方向。

public void Print(List ListToBePrinted) 
{ 
    PrintDialog SelectedPrinter = new PrintDialog(); 
    if (SelectedPrinter.ShowDialog() == true) 
    { 
     PrintCapabilities printerCapabilities = SelectedPrinter.PrintQueue.GetPrintCapabilities(); 
     Size PageSize = new Size(printerCapabilities.PageImageableArea.ExtentWidth, printerCapabilities.PageImageableArea.ExtentHeight); 
     Size PrintableImageSize = new Size(); 
     foreach (Uri aUri in ListToBePrinted) 
     { 
      DrawingVisual drawVisual = new DrawingVisual(); 
      ImageBrush imageBrush = new ImageBrush(); 
      imageBrush.ImageSource = new BitmapImage(aUri); 
      imageBrush.Stretch = Stretch.Fill; 
      imageBrush.TileMode = TileMode.None; 
      imageBrush.AlignmentX = AlignmentX.Center; 
      imageBrush.AlignmentY = AlignmentY.Center; 
      if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height) 
       PrintableImageSize = new Size(768, 576); //8x6 
      else PrintableImageSize = new Size(576, 768); //6x8 
      double xcor = 0; double ycor = 0; 
      if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height) 
      { 
       if ((PageSize.Width - PrintableImageSize.Height) > 0) 
        xcor = (PageSize.Width - PrintableImageSize.Height)/2; 
       if ((PageSize.Height - PrintableImageSize.Width) > 0) 
        ycor = (PageSize.Height - PrintableImageSize.Width)/2; 
      } 
      else 
      { 
       if ((PageSize.Width - PrintableImageSize.Width) > 0) 
        xcor = (PageSize.Width - PrintableImageSize.Width)/2; 
       if ((PageSize.Height - PrintableImageSize.Height) > 0) 
        ycor = (PageSize.Height - PrintableImageSize.Height)/2; 
      } 
      using (DrawingContext drawingContext = drawVisual.RenderOpen()) 
      { 
       if (imageBrush.ImageSource.Width > imageBrush.ImageSource.Height) 
       { 
        drawingContext.PushTransform(new RotateTransform(90, PrintableImageSize.Width/2, PrintableImageSize.Height/2)); 
       } 
       drawingContext.DrawRectangle(imageBrush, null, new Rect(xcor, ycor, PrintableImageSize.Width, PrintableImageSize.Height)); 
      } 
      SelectedPrinter.PrintVisual(drawVisual, "Print"); 
     } 
    } 
} 
+0

@digEmAll:这是一些快速的编辑! – Nick 2011-03-15 16:00:58

+0

@Nick:上帝保佑Visual Studio中自动格式功能;-) – digEmAll 2011-03-15 16:01:59

回答

0

结帐的HardMarginX和HardMarginY值,如果你能找到他们。

我在我的应用程序之一(其中e是一个PrintPageEventArgs)这个代码

e.Graphics.DrawImage(nextImage, e.PageSettings.PrintableArea.X - e.PageSettings.HardMarginX, e.PageSettings.PrintableArea.Y - e.PageSettings.HardMarginY, e.PageSettings.Landscape ? e.PageSettings.PrintableArea.Height : e.PageSettings.PrintableArea.Width, e.PageSettings.Landscape ? e.PageSettings.PrintableArea.Width : e.PageSettings.PrintableArea.Height); 

我的打印功能是有点原始,但也许你可以根据硬盘的利润调整XCOR和YCOR。

+0

我可以用0,0 XCOR和YCOR如果我想打印完整的网页?我尝试过,但它似乎没有工作 – vinee 2011-03-16 13:48:21

+0

我试过0,0 XCOR和YCOR和所有的利润为0,即使再有照片周围的微小的利润。我怎样才能获得无边距打印? – vinee 2011-03-16 16:55:44