Graphics.CopyFromScreen的输出可以扩展到A4尺寸吗?

时间:2010-10-20 06:09:29

标签: c# .net

以下代码将屏幕输出为JPEG。在A4上打印时,它几乎不占据高度的一半。是否可以扩展到827 x 1169,即A4尺寸?

谢谢Chakra。

public void TakeScreenshot() 
    { 

        Rectangle bounds = Screen.PrimaryScreen.Bounds; 
        using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb)) 
           { 

            using (Graphics gfx = Graphics.FromImage(bmp)) 
              { 

               gfx.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy); 

               Stream myStream;
               SaveFileDialog saveFileDialog1 = new SaveFileDialog();

               saveFileDialog1.Filter = "jpeg files (*.jpeg)|*.jpeg";
               saveFileDialog1.FilterIndex = 2;
               saveFileDialog1.RestoreDirectory = true;

               if (saveFileDialog1.ShowDialog() == DialogResult.OK)
               {
                  if ((myStream = saveFileDialog1.OpenFile()) != null)
                  {
                     // Code to write the stream goes here.
                        bmp.Save(myStream, ImageFormat.Jpeg);
                        myStream.Close();
                   }
               }
             } 
          } 

    }

1 个答案:

答案 0 :(得分:0)

您可能需要以某种方式调整图像的dpi以将其拉伸至A4的大小