Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言在相纸上打印图片#_C#_Printing - Fatal编程技术网

C# 用C语言在相纸上打印图片#

C# 用C语言在相纸上打印图片#,c#,printing,C#,Printing,我必须用DNP DS620打印机打印图片。这幅画是印刷品,但不是全部。这是我的密码: PrintController printController = new StandardPrintController(); pd.PrintController = printController; pd.DefaultPageSettings.Margins = new Margins(0,0, 0, 0); pd.PrinterSettings.DefaultPageSettings.Margins

我必须用DNP DS620打印机打印图片。这幅画是印刷品,但不是全部。这是我的密码:

PrintController printController = new StandardPrintController();
pd.PrintController = printController;
pd.DefaultPageSettings.Margins = new Margins(0,0, 0, 0);
pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

pd.PrintPage += (sndr, args) =>
{
    System.Drawing.Image i = System.Drawing.Image.FromFile(@"C:\Users\EMOSI\Desktop\photo36.jpg");

    //Adjust the size of the image to the page to print the full image without loosing any part of the image.
    System.Drawing.Rectangle m = args.MarginBounds;

    //Logic below maintains Aspect Ratio.
    if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) // image is wider
    {
         m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width)-20;
         m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height) +10 ; // ajouter +
    }
    else
    {
         m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height)-20;
    }

    //Calculating optimal orientation.
    pd.DefaultPageSettings.Landscape = m.Width > m.Height;

    //Putting image in center of page.
    m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Height) / 2);
    m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Width) / 2)-10; //chiffre bon
    args.Graphics.DrawImage(i, m);
};
pd.Print();

我怎样才能打印完整的图片?使用此代码,图片从左侧剪切。纸张大小为6x4,通过Windows打印效果很好。

我找到了答案。这是代码,给那些有兴趣的人

PrintDocument pd = new PrintDocument();
PrintController printController = new StandardPrintController();
pd.PrintController = printController;
pd.DefaultPageSettings.Margins = new Margins(0,0, 0, 0);
pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 17);

pd.PrintPage += (sndr, args) =>
{
     System.Drawing.Image i = System.Drawing.Image.FromFile(@"C:\Users\EMOSI\Desktop\photo36.jpg");

     //Adjust the size of the image to the page to print the full image without loosing any part of the image.
     System.Drawing.Rectangle m = args.MarginBounds;

     //Logic below maintains Aspect Ratio.
     if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) // image is wider
     {
          m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width)-20;
          m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height) +5; // ajouter +
     }
     else
     {
          m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
     }

     //Calculating optimal orientation.
     pd.DefaultPageSettings.Landscape = m.Width > m.Height;

     //Putting image in center of page.
     m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Height) / 2);
     m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Width) / 2) - 2; //chiffre bon
     args.Graphics.DrawImage(i, m);
};
pd.Print();

我找到了答案。这是代码,给那些有兴趣的人

PrintDocument pd = new PrintDocument();
PrintController printController = new StandardPrintController();
pd.PrintController = printController;
pd.DefaultPageSettings.Margins = new Margins(0,0, 0, 0);
pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 17);

pd.PrintPage += (sndr, args) =>
{
     System.Drawing.Image i = System.Drawing.Image.FromFile(@"C:\Users\EMOSI\Desktop\photo36.jpg");

     //Adjust the size of the image to the page to print the full image without loosing any part of the image.
     System.Drawing.Rectangle m = args.MarginBounds;

     //Logic below maintains Aspect Ratio.
     if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) // image is wider
     {
          m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width)-20;
          m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height) +5; // ajouter +
     }
     else
     {
          m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
     }

     //Calculating optimal orientation.
     pd.DefaultPageSettings.Landscape = m.Width > m.Height;

     //Putting image in center of page.
     m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Height) / 2);
     m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Width) / 2) - 2; //chiffre bon
     args.Graphics.DrawImage(i, m);
};
pd.Print();

用英语概述解决方案所涉及的内容,而不仅仅是代码转储,可能会对其他人有所帮助。用英语概述解决方案所涉及的内容,而不仅仅是代码转储,可能会对其他人有所帮助