2

ユーザーのデスクトップ全体を画像としてキャプチャしようとしています。私はこれを次のように行います:

        public Bitmap CaptureScreen()
    {
        // Set up a bitmap of the correct size
        Bitmap CapturedImage = new Bitmap((int)SystemInformation.VirtualScreen.Width,
            (int)SystemInformation.VirtualScreen.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        // Create a graphics object from it
        System.Drawing.Size size = new System.Drawing.Size((int)SystemInformation.VirtualScreen.Width, (int)SystemInformation.VirtualScreen.Height);

        using (Graphics g = Graphics.FromImage(CapturedImage))
        {
            // copy the entire screen to the bitmap
            g.CopyFromScreen(0, 0, 0, 0,
                size, CopyPixelOperation.SourceCopy);
        }
        return CapturedImage;
    }

PixelFormatただし、をからFormat32bppArgbに変更しようとするとFormat16bppArgb1555OutOfMemoryException品質が低下したことを考えると、よくわかりません。

何か案は?または、どうすればこの画像の品質を下げることができますか(非常に頻繁にネットワーク経由で送信されるため)

4

1 に答える 1

7

ドキュメントから:(関連もあります)

この[ FromImage()]メソッドは、画像が次のピクセル形式のいずれかである場合にも例外をスローします。

  • 未定義
  • DontCare
  • Format16bppArgb1555
  • Format16bppGrayScale

「関連する」リンクで、msdnは次のように述べています。

ここでの唯一の問題は、この状況ではOutOfMessageExceptionがあまり正確な例外タイプではないことです。VS2010以降のリリースで修正することを検討します。

于 2012-07-06T19:26:41.907 に答える