This program is eventually going to be a screen recorder, but right now I just want it to capture screen images.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Drawing;
using System.Windows.Forms;
namespace ScreenRecorder
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static bool recording = false;
public static string saveAddress = @"C:\Users\UserName\Desktop\something.bmp";
public MainWindow()
{
InitializeComponent();
}
private void onClick(object sender, RoutedEventArgs e)
{
System.Drawing.Image currentImage;
if (recording == false)
{
currentImage = this.CaptureScreen();
recording = true;
recorderButton.Content = "Stop Recording!";
currentImage.Save(saveAddress);
}
else
{
recording = false;
recorderButton.Content = "Start Recording!";
}
}
private System.Drawing.Image CaptureScreen()
{
System.Drawing.Rectangle screenSize = Screen.PrimaryScreen.Bounds;
Bitmap target = new Bitmap(screenSize.Width, screenSize.Height);
using (Graphics g = Graphics.FromImage(target))
{
g.CopyFromScreen(0, 0, 0, 0, new System.Drawing.Size(screenSize.Width, screenSize.Height));
}
return target;
}
}
}