2017-01-20 1 views
2

私はスクリーンショットをつかんで、一定の間隔でイメージの形で保存するソリューションに取り組んでいます。このアプリケーションはWindowsフォームに組み込まれています。私は、画面の解像度を取得するために以下のコードを使用しているスクリーンショットをキャプチャするためのWindowsフォームアプリケーションでモニタの画面サイズを取得する方法は?

- :

int h = Screen.PrimaryScreen.WorkingArea.Height; 
int w = Screen.PrimaryScreen.WorkingArea.Width; 

これは、1366×768の解像度を持つノートパソコンで正常に動作します。

しかし、非常に大きなモニターで同じアプリケーションを実行すると、画像が右下から切り取られます。

コード内のモニターサイズを処理する方法はありますか。

+0

は[「作業領域は、タスクバー、ドッキングウィンドウ、およびドッキングツールバーを除く、ディスプレイのデスクトップ領域です。」 ](https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea)。代わりに['Screen.Bounds'](https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.bounds)を使用して画面全体を取得できます – Slai

答えて

1

フォームを含む画面をキャプチャする場合は、Screen.FromControl methodを使用してフォームインスタンスを渡し、その画面のWorkingAreaを使用します。

この前提が間違っている場合は、質問に詳細を追加してください。

0

このコードは、複数の画面を行います...その私が使用して...

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Drawing; 
using System.Drawing.Imaging; 
using System.Windows.Forms; 
using System.IO; 

namespace JeremyThompsonLabs 
{ 
    public class Screenshot 
    { 
     public static string TakeScreenshotReturnFilePath() 
     { 
      int screenLeft = SystemInformation.VirtualScreen.Left; 
      int screenTop = SystemInformation.VirtualScreen.Top; 
      int screenWidth = SystemInformation.VirtualScreen.Width; 
      int screenHeight = SystemInformation.VirtualScreen.Height; 

      // Create a bitmap of the appropriate size to receive the screenshot. 
      using (Bitmap bitmap = new Bitmap(screenWidth, screenHeight)) 
      { 
       // Draw the screenshot into our bitmap. 
       using (Graphics g = Graphics.FromImage(bitmap)) 
       { 
        g.CopyFromScreen(screenLeft, screenTop, 0, 0, bitmap.Size); 
       } 

       var uniqueFileName = Path.Combine(System.IO.Path.GetTempPath(), Path.GetRandomFileName().Replace(".", string.Empty) + ".jpeg"); 
       try 
       { 
        bitmap.Save(uniqueFileName, ImageFormat.Jpeg); 
       } 
       catch (Exception ex) 
       { 
        return string.Empty; 
       } 
       return uniqueFileName; 
      } 
     } 

    } 
} 
関連する問題