#

Net WinForms: Screen zu Bitmap

 

 

Mit dem folgenden Code kann man schnell ein Bitmap Image vom aktuellen Screen-Bildschirm erstellen.

 

Betrifft: Winforms

 

Vorgehensweise:

1)    Erstelle leere Bitmap mit Größe des Bildschirms

2)    Erstelle ein Graphics Objekt aus diesem leeren Bitmap

3)    Fülle das Graphics.Bitmap mit CopyFromScreen

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace winform_Bitmap_from_Screen

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            Bitmap screenshot = new Bitmap(SystemInformation.VirtualScreen.Width,

                               SystemInformation.VirtualScreen.Height,

                               System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Graphics screenGraph = Graphics.FromImage(screenshot);

            screenGraph.CopyFromScreen(SystemInformation.VirtualScreen.X,

                                       SystemInformation.VirtualScreen.Y,

                                       0,

                                       0,

                                       SystemInformation.VirtualScreen.Size,

                                       CopyPixelOperation.SourceCopy);

 

            screenshot.Save("C:\\_Daten\\Desktop\\Test\\_screenshots\\Screenshot.png", System.Drawing.Imaging.ImageFormat.Png);

        }

    }

}

 

Mobile

.

123movies