-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageClippingWindow.xaml.cs
74 lines (59 loc) · 2.39 KB
/
ImageClippingWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows;
namespace SNIBypassGUI
{
/// <summary>
/// ImageClippingWindow.xaml 的交互逻辑
/// </summary>
public partial class ImageClippingWindow : Window
{
private string imagePath;
public ImageClippingWindow(string _imagePath)
{
InitializeComponent();
imagePath = _imagePath;
// 窗口可拖动
this.TopBar.MouseLeftButtonDown += (o, e) => { DragMove(); };
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// 加载图片
ImageCropperControl.LoadImageFromFile(imagePath);
}
private void OKBtn_Click(object sender, RoutedEventArgs e)
{
// 定义裁剪区域
Rectangle cropArea = new Rectangle((int)ImageCropperControl.CroppedRegion.X, (int)ImageCropperControl.CroppedRegion.Y, (int)ImageCropperControl.CroppedRegion.Width, (int)ImageCropperControl.CroppedRegion.Height);
// 加载图片
Bitmap original = new Bitmap(imagePath);
// 创建一个新的Bitmap对象,大小与裁剪区域一致
Bitmap croppedImage = new Bitmap(cropArea.Width, cropArea.Height);
// 创建Graphics对象,绘制裁剪后的图像
using (Graphics g = Graphics.FromImage(croppedImage))
{
// 执行裁剪操作,将裁剪区域绘制到新的图像中
g.DrawImage(original, new Rectangle(0, 0, cropArea.Width, cropArea.Height), cropArea, GraphicsUnit.Pixel);
}
// 保存裁剪后的图片
croppedImage.Save(Path.Combine(PathsSet.CustomBackground));
this.DialogResult = true;
this.Close();
}
private void ResetBtn_Click(object sender, RoutedEventArgs e)
{
ImageCropperControl.ResetDrawThumb();
}
private void CancelBtn_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
private void HelpBtn_Click(object sender, RoutedEventArgs e)
{
HelpBadge.Visibility = Visibility.Collapsed;
Process.Start(new ProcessStartInfo(LinksSet.如何使用自定义背景功能) { UseShellExecute = true });
}
}
}