You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
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.Drawing.Imaging;
|
|
using System.Diagnostics;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Capture
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private OptionContext _options;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
InitInstance();
|
|
}
|
|
|
|
private void InitInstance()
|
|
{
|
|
_options = this.DataContext as OptionContext;
|
|
}
|
|
|
|
private void CaptureScreen()
|
|
{
|
|
int width = (int)this.Width - _options.FrameThickness * 2;
|
|
int height = (int)this.Height - _options.FrameThickness * 2 - _options.ButtonHeight;
|
|
int left = (int)this.Left + _options.FrameThickness;
|
|
int top = (int)this.Top + _options.FrameThickness;
|
|
|
|
string path = @"C:\Temp\test.bmp";
|
|
using (Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
|
|
{
|
|
using (Graphics gr = Graphics.FromImage(bitmap))
|
|
{
|
|
gr.CopyFromScreen(left, top, 0, 0, bitmap.Size);
|
|
}
|
|
|
|
bitmap.Save(path, ImageFormat.Png);
|
|
}
|
|
|
|
OpenFile(path);
|
|
}
|
|
|
|
private void OpenFile(string path)
|
|
{
|
|
Process pr = new Process();
|
|
pr.StartInfo = new ProcessStartInfo(path)
|
|
{
|
|
UseShellExecute = true
|
|
};
|
|
pr.Start();
|
|
}
|
|
|
|
private void btnCapture_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CaptureScreen();
|
|
}
|
|
|
|
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e.ChangedButton != MouseButton.Left)
|
|
return;
|
|
|
|
this.DragMove();
|
|
}
|
|
}
|
|
}
|
|
|