2010-10-20 82 views
0

以下代碼將屏幕輸出到JPEG。在A4上打印時,幾乎不佔據高度的一半。是否可以按比例縮小至827 x 1169,即A4尺寸?Graphics.CopyFromScreen的輸出可以放大到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(); 
        } 
       } 
      } 
      } 

    } 

回答

0

你可能需要調整圖像的DPI以某種方式對其進行拉伸到一個A4大小

+0

好,不過這會降低圖像的質量是不是? – Chakra 2010-10-20 07:31:19

+0

是的,這會導致紙張質量下降,因爲您必須縮放源代碼 – 2010-10-20 10:22:01