Skip to content

Commit 49d7c67

Browse files
authored
Add files via upload
1 parent d483a06 commit 49d7c67

File tree

7 files changed

+231
-14
lines changed

7 files changed

+231
-14
lines changed

Main/MainWindow.xaml.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Windows.Controls;
77
using System.Windows.Ink;
88
using System.Windows.Input;
9+
using System.Windows.Media;
910
using System.Windows.Media.Imaging;
1011
using WinForms = System.Windows.Forms;
1112
using ShowWrite.Models;
@@ -30,6 +31,10 @@ private enum ToolMode { None, Move, Pen, Eraser }
3031
private D.Point _lastMousePos;
3132
private bool _isPanning = false;
3233

34+
// 新增:缩放比例 & 用户笔宽
35+
private double currentZoom = 1.0;
36+
private double userPenWidth = 2.0;
37+
3338
public MainWindow()
3439
{
3540
InitializeComponent();
@@ -55,9 +60,17 @@ public MainWindow()
5560
{
5661
MessageBox.Show("未找到可用摄像头。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
5762
}
63+
64+
UpdatePenAttributes();
65+
}
66+
67+
private void UpdatePenAttributes()
68+
{
69+
Ink.DefaultDrawingAttributes.Width = userPenWidth / currentZoom;
70+
Ink.DefaultDrawingAttributes.Height = userPenWidth / currentZoom;
5871
}
5972

60-
#region ģʽ�л�
73+
#region 模式切换
6174
private void SetMode(ToolMode mode, bool initial = false)
6275
{
6376
_currentMode = mode;
@@ -85,18 +98,19 @@ private void SetMode(ToolMode mode, bool initial = false)
8598
private void MoveBtn_Click(object sender, RoutedEventArgs e)
8699
{
87100
if (_currentMode != ToolMode.Move) SetMode(ToolMode.Move);
88-
else MoveBtn.IsChecked = true; // ��ֹȡ��ѡ��
101+
else MoveBtn.IsChecked = true;
89102
}
90103

91104
private void PenBtn_Click(object sender, RoutedEventArgs e)
92105
{
93106
if (_currentMode == ToolMode.Pen)
94107
{
95-
var dlg = new WinForms.ColorDialog();
96-
if (dlg.ShowDialog() == WinForms.DialogResult.OK)
108+
var dlg = new PenSettingsWindow(Ink.DefaultDrawingAttributes.Color, userPenWidth);
109+
if (dlg.ShowDialog() == true)
97110
{
98-
Ink.DefaultDrawingAttributes.Color = System.Windows.Media.Color.FromArgb(
99-
dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
111+
Ink.DefaultDrawingAttributes.Color = dlg.SelectedColor;
112+
userPenWidth = dlg.SelectedWidth;
113+
UpdatePenAttributes();
100114
}
101115
PenBtn.IsChecked = true;
102116
}
@@ -106,6 +120,8 @@ private void PenBtn_Click(object sender, RoutedEventArgs e)
106120
}
107121
}
108122

123+
124+
109125
private void EraserBtn_Click(object sender, RoutedEventArgs e)
110126
{
111127
if (_currentMode != ToolMode.Eraser) SetMode(ToolMode.Eraser);
@@ -151,8 +167,10 @@ private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
151167
if (_currentMode == ToolMode.Move || _currentMode == ToolMode.Pen)
152168
{
153169
double zoom = e.Delta > 0 ? 1.1 : 0.9;
154-
ZoomTransform.ScaleX *= zoom;
155-
ZoomTransform.ScaleY *= zoom;
170+
currentZoom *= zoom;
171+
ZoomTransform.ScaleX = currentZoom;
172+
ZoomTransform.ScaleY = currentZoom;
173+
UpdatePenAttributes();
156174
}
157175
}
158176

@@ -175,11 +193,12 @@ private void VideoArea_ManipulationDelta(object sender, ManipulationDeltaEventAr
175193
return;
176194

177195
var delta = e.DeltaManipulation;
178-
179-
ZoomTransform.ScaleX *= delta.Scale.X;
180-
ZoomTransform.ScaleY *= delta.Scale.Y;
196+
currentZoom *= delta.Scale.X;
197+
ZoomTransform.ScaleX = currentZoom;
198+
ZoomTransform.ScaleY = currentZoom;
181199
PanTransform.X += delta.Translation.X;
182200
PanTransform.Y += delta.Translation.Y;
201+
UpdatePenAttributes();
183202

184203
e.Handled = true;
185204
}
@@ -310,9 +329,6 @@ private void OpenPerspectiveCorrection_Click(object sender, RoutedEventArgs e)
310329
}
311330
}
312331

313-
#endregion
314-
315-
#region ���߷���
316332
private BitmapImage BitmapToBitmapImage(D.Bitmap bitmap)
317333
{
318334
using var memory = new MemoryStream();

Main/PenSettingsWindow.xaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Window x:Class="ShowWrite.PenSettingsWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="画笔设置" Height="251" Width="320"
5+
WindowStartupLocation="CenterOwner" ResizeMode="NoResize">
6+
<StackPanel Margin="15,15,15,10">
7+
<!-- 颜色选择 -->
8+
<TextBlock Text="选择颜色:" FontWeight="Bold" Margin="0,0,0,5"/>
9+
<Button x:Name="ColorButton" Content="打开调色盘" Click="ColorButton_Click" Width="120"/>
10+
<Border x:Name="ColorPreview" Width="50" Height="20" BorderBrush="Black" BorderThickness="1" Margin="5"/>
11+
12+
<!-- 宽度选择 -->
13+
<TextBlock Text="选择笔宽:" FontWeight="Bold" Margin="0,15,0,5"/>
14+
<Slider x:Name="WidthSlider" Minimum="1" Maximum="20" Value="2" TickFrequency="1" IsSnapToTickEnabled="True"/>
15+
<TextBlock x:Name="WidthValue" Text="宽度: 2" Margin="0,5,0,0"/>
16+
17+
<!-- 按钮 -->
18+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,0,0">
19+
<Button Content="确定" Width="80" Margin="5" Click="Ok_Click"/>
20+
<Button Content="取消" Width="80" Margin="5" Click="Cancel_Click"/>
21+
</StackPanel>
22+
</StackPanel>
23+
</Window>

Main/PenSettingsWindow.xaml.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Windows;
2+
using System.Windows.Media;
3+
using WinForms = System.Windows.Forms;
4+
5+
namespace ShowWrite
6+
{
7+
public partial class PenSettingsWindow : Window
8+
{
9+
public System.Windows.Media.Color SelectedColor { get; private set; }
10+
public double SelectedWidth { get; private set; }
11+
12+
public PenSettingsWindow(System.Windows.Media.Color currentColor, double currentWidth)
13+
{
14+
InitializeComponent();
15+
16+
SelectedColor = currentColor;
17+
SelectedWidth = currentWidth;
18+
19+
ColorPreview.Background = new SolidColorBrush(SelectedColor);
20+
WidthSlider.Value = SelectedWidth;
21+
WidthValue.Text = $"宽度: {SelectedWidth}";
22+
23+
WidthSlider.ValueChanged += (s, e) =>
24+
{
25+
WidthValue.Text = $"宽度: {(int)e.NewValue}";
26+
};
27+
}
28+
29+
private void ColorButton_Click(object sender, RoutedEventArgs e)
30+
{
31+
var dlg = new WinForms.ColorDialog();
32+
dlg.Color = System.Drawing.Color.FromArgb(SelectedColor.A, SelectedColor.R, SelectedColor.G, SelectedColor.B);
33+
if (dlg.ShowDialog() == WinForms.DialogResult.OK)
34+
{
35+
SelectedColor = System.Windows.Media.Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
36+
ColorPreview.Background = new SolidColorBrush(SelectedColor);
37+
}
38+
}
39+
40+
private void Ok_Click(object sender, RoutedEventArgs e)
41+
{
42+
SelectedWidth = WidthSlider.Value;
43+
DialogResult = true;
44+
}
45+
46+
private void Cancel_Click(object sender, RoutedEventArgs e)
47+
{
48+
DialogResult = false;
49+
}
50+
}
51+
}

Main/ShowWrite.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36408.4 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowWrite", "ShowWrite.csproj", "{1FEBD063-10B8-47FD-A2A6-B3F3270EB83C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1FEBD063-10B8-47FD-A2A6-B3F3270EB83C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1FEBD063-10B8-47FD-A2A6-B3F3270EB83C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1FEBD063-10B8-47FD-A2A6-B3F3270EB83C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1FEBD063-10B8-47FD-A2A6-B3F3270EB83C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {498B59E3-5F1C-47BD-847B-FA5396092713}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Window x:Class="ShowWrite.Views.RealTimePerspectiveCorrectionWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="实时梯形校正" Height="450" Width="600"
5+
WindowStartupLocation="CenterOwner"
6+
Background="#2b2b2b">
7+
<Grid>
8+
<Grid.RowDefinitions>
9+
<RowDefinition Height="*"/>
10+
<RowDefinition Height="Auto"/>
11+
</Grid.RowDefinitions>
12+
13+
<!-- 视频预览和点选择 -->
14+
<Image x:Name="PreviewImage" Grid.Row="0" Stretch="Uniform" MouseDown="Image_MouseDown"/>
15+
16+
<!-- 控制按钮 -->
17+
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="10">
18+
<Button Content="确定" Width="100" Height="40" Margin="10" Click="OK_Click"/>
19+
<Button Content="取消" Width="100" Height="40" Margin="10" Click="Cancel_Click"/>
20+
<Button Content="重置" Width="100" Height="40" Margin="10" Click="Reset_Click"/>
21+
</StackPanel>
22+
23+
<!-- 点标记 -->
24+
<Canvas x:Name="MarkersCanvas" Grid.Row="0" IsHitTestVisible="False"/>
25+
</Grid>
26+
</Window>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System.Collections.Generic;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using System.Windows.Input;
5+
using System.Windows.Media;
6+
using System.Windows.Shapes;
7+
8+
namespace ShowWrite.Views
9+
{
10+
public partial class RealTimePerspectiveCorrectionWindow : Window
11+
{
12+
private readonly List<System.Windows.Point> _points = new List<System.Windows.Point>();
13+
private readonly List<Ellipse> _markers = new List<Ellipse>();
14+
15+
public System.Windows.Point[] SelectedPoints => _points.ToArray();
16+
17+
public RealTimePerspectiveCorrectionWindow()
18+
{
19+
InitializeComponent();
20+
}
21+
22+
public void SetImageSource(ImageSource source)
23+
{
24+
PreviewImage.Source = source;
25+
}
26+
27+
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
28+
{
29+
if (_points.Count >= 4) return;
30+
31+
var position = e.GetPosition(PreviewImage);
32+
_points.Add(position); // 使用 System.Windows.Point
33+
34+
// 添加标记
35+
var ellipse = new Ellipse
36+
{
37+
Width = 10,
38+
Height = 10,
39+
Fill = System.Windows.Media.Brushes.Red,
40+
Stroke = System.Windows.Media.Brushes.White,
41+
StrokeThickness = 2
42+
};
43+
44+
Canvas.SetLeft(ellipse, position.X - 5);
45+
Canvas.SetTop(ellipse, position.Y - 5);
46+
MarkersCanvas.Children.Add(ellipse);
47+
_markers.Add(ellipse);
48+
}
49+
50+
private void OK_Click(object sender, RoutedEventArgs e)
51+
{
52+
if (_points.Count == 4)
53+
{
54+
DialogResult = true;
55+
Close();
56+
}
57+
else
58+
{
59+
System.Windows.MessageBox.Show("请选择4个点进行梯形校正", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
60+
}
61+
}
62+
63+
private void Cancel_Click(object sender, RoutedEventArgs e)
64+
{
65+
DialogResult = false;
66+
Close();
67+
}
68+
69+
private void Reset_Click(object sender, RoutedEventArgs e)
70+
{
71+
_points.Clear();
72+
MarkersCanvas.Children.Clear();
73+
_markers.Clear();
74+
}
75+
}
76+
}

Main/icon-d1tools.com.ico

270 KB
Binary file not shown.

0 commit comments

Comments
 (0)