Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutomaticUpdateVersionControl.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.17.0
1.7.18.0
64 changes: 55 additions & 9 deletions Ink Canvas/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class App : Application
Mutex mutex;

public static string[] StartArgs;
public static string RootPath = Environment.GetEnvironmentVariable("APPDATA") + "\\Ink Canvas\\";
public static string RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

// 新增:标记是否通过--board参数启动
public static bool StartWithBoardMode = false;
Expand All @@ -46,7 +46,7 @@ public partial class App : Application
// 新增:退出信号文件路径
private static string watchdogExitSignalFile = Path.Combine(Path.GetTempPath(), "icc_watchdog_exit_" + Process.GetCurrentProcess().Id + ".flag");
// 新增:崩溃日志文件路径
private static string crashLogFile = Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), "Ink Canvas", "crash_logs");
private static string crashLogFile = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Crashes");
// 新增:进程ID
private static int currentProcessId = Process.GetCurrentProcess().Id;
// 新增:应用启动时间
Expand Down Expand Up @@ -107,7 +107,6 @@ private void ConfigureTlsForWindows7()

if (isWindows7)
{
LogHelper.WriteLogToFile("检测到Windows 7系统,配置TLS协议支持");

// 启用所有TLS版本以支持Windows 7
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Expand All @@ -117,17 +116,14 @@ private void ConfigureTlsForWindows7()
ServicePointManager.Expect100Continue = false;
ServicePointManager.UseNagleAlgorithm = false;

LogHelper.WriteLogToFile("TLS协议配置完成,已启用TLS 1.2/1.1/1.0支持");
}
else
{
// 对于更新的Windows版本,不进行任何TLS配置,使用系统默认设置
LogHelper.WriteLogToFile($"检测到Windows版本: {osVersion.VersionString},使用系统默认TLS配置");
}
}
catch (Exception ex)
catch (Exception)
{
LogHelper.WriteLogToFile($"配置TLS协议时出错: {ex.Message}", LogHelper.LogType.Error);
}
}

Expand Down Expand Up @@ -346,6 +342,25 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
try
{
var exception = e.ExceptionObject as Exception;

if (exception is InvalidOperationException invalidOpEx)
{
string exceptionMessage = invalidOpEx.Message ?? "";
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";

if (exceptionMessage.Contains("调用线程无法访问此对象") ||
exceptionMessage.Contains("because another thread owns it") ||
exceptionStackTrace.Contains("DynamicRenderer") ||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
{
LogHelper.WriteLogToFile(
$"检测到DynamicRenderer线程访问异常: {invalidOpEx.Message}",
LogHelper.LogType.Warning
);
return;
}
}

string errorMessage = exception?.ToString() ?? "未知异常";
lastErrorMessage = errorMessage;

Expand All @@ -361,8 +376,11 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
// 尝试在最后时刻记录错误
try
{
string timeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
File.AppendAllText(
Path.Combine(crashLogFile, $"critical_error_{DateTime.Now:yyyyMMdd_HHmmss}.log"),
Path.Combine(crashLogFile, $"Crash_{timeStr}.txt"),
$"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] 记录未处理异常时发生错误: {ex.Message}\r\n"
);
}
Expand Down Expand Up @@ -500,7 +518,10 @@ private static void WriteCrashLog(string message)
Directory.CreateDirectory(crashLogFile);
}

string logFileName = Path.Combine(crashLogFile, $"crash_{DateTime.Now:yyyyMMdd}.log");
string appStartTimeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string logFileName = Path.Combine(crashLogFile, $"Crash_{appStartTimeStr}.txt");

// 收集系统状态信息
string memoryUsage = (Process.GetCurrentProcess().WorkingSet64 / (1024 * 1024)) + " MB";
Expand Down Expand Up @@ -549,6 +570,31 @@ public static void SyncCrashActionFromSettings()

private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// 检查是否是DynamicRenderer线程访问UI对象的已知问题
if (e.Exception is InvalidOperationException invalidOpEx)
{
string exceptionMessage = invalidOpEx.Message ?? "";
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";

// 检查是否是DynamicRenderer相关的线程访问问题
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
exceptionMessage.Contains("because another thread owns it") ||
exceptionStackTrace.Contains("DynamicRenderer") ||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
{
// 这是WPF InkCanvas的已知问题,DynamicRenderer的后台线程尝试访问UI对象
// 这个异常不会影响应用程序功能,可以安全地忽略
LogHelper.WriteLogToFile(
$"检测到DynamicRenderer线程访问异常(已安全处理): {invalidOpEx.Message}",
LogHelper.LogType.Warning
);

// 标记为已处理,不显示错误消息,不触发重启
e.Handled = true;
return;
}
}

Ink_Canvas.MainWindow.ShowNewMessage("抱歉,出现未预期的异常,可能导致 InkCanvasForClass 运行不稳定。\n建议保存墨迹后重启应用。");
LogHelper.NewLog(e.Exception.ToString());

Expand Down
4 changes: 2 additions & 2 deletions Ink Canvas/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.17.2")]
[assembly: AssemblyFileVersion("1.7.17.2")]
[assembly: AssemblyVersion("1.7.18.0")]
[assembly: AssemblyFileVersion("1.7.18.0")]
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<Window x:Class="Ink_Canvas.QuickDrawFloatingButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Topmost="True" Background="Transparent"
mc:Ignorable="d" WindowStyle="None" AllowsTransparency="True"
Loaded="FloatingButton_Loaded" WindowStartupLocation="Manual"
ShowInTaskbar="False" Focusable="False"
Title="快抽悬浮按钮" Height="45" Width="65">

<Window.Resources>
<UserControl x:Class="Ink_Canvas.Controls.QuickDrawFloatingButtonControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="65" Height="45">

<UserControl.Resources>
<ResourceDictionary>
<!-- 悬浮按钮资源 -->
<SolidColorBrush x:Key="QuickDrawFloatingButtonBackground" Color="#80000000"/>
<SolidColorBrush x:Key="QuickDrawFloatingButtonBorderBrush" Color="#40000000"/>
<SolidColorBrush x:Key="QuickDrawFloatingButtonIconForeground" Color="White"/>
</ResourceDictionary>
</Window.Resources>
</UserControl.Resources>

<Border Background="{DynamicResource QuickDrawFloatingButtonBackground}"
CornerRadius="8"
Expand Down Expand Up @@ -85,4 +82,5 @@
</Border>
</Grid>
</Border>
</Window>
</UserControl>

149 changes: 149 additions & 0 deletions Ink Canvas/Controls/QuickDrawFloatingButtonControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using Ink_Canvas.Windows;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
using VerticalAlignment = System.Windows.VerticalAlignment;

namespace Ink_Canvas.Controls
{
/// <summary>
/// 快抽悬浮按钮控件
/// </summary>
public partial class QuickDrawFloatingButtonControl : UserControl
{
private bool _isDragging = false;
private Point _dragStartPoint;
private Point _controlStartPoint;

public QuickDrawFloatingButtonControl()
{
InitializeComponent();
}

/// <summary>
/// 快抽按钮点击事件
/// </summary>
private void FloatingButton_Click(object sender, MouseButtonEventArgs e)
{
try
{
// 如果正在拖动,不触发点击事件
if (_isDragging) return;

// 打开快抽窗口
var quickDrawWindow = new QuickDrawWindow();
quickDrawWindow.ShowDialog();
}
catch (Exception ex)
{
Helpers.LogHelper.WriteLogToFile($"打开快抽窗口失败: {ex.Message}", Helpers.LogHelper.LogType.Error);
}
}

/// <summary>
/// 拖动区域鼠标按下事件
/// </summary>
private void DragArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_isDragging = false;

// 记录鼠标在屏幕上的初始位置
_dragStartPoint = this.PointToScreen(e.GetPosition(this));

// 记录控件的初始位置
var parent = this.Parent as FrameworkElement;
if (parent != null)
{
var transform = this.TransformToVisual(parent);
var currentPos = transform.Transform(new Point(0, 0));
_controlStartPoint = currentPos;
}
else
{
var currentMargin = this.Margin;
_controlStartPoint = new Point(
double.IsNaN(currentMargin.Left) ? 0 : currentMargin.Left,
double.IsNaN(currentMargin.Top) ? 0 : currentMargin.Top);
}

((UIElement)sender).CaptureMouse();
e.Handled = true;
}

/// <summary>
/// 拖动区域鼠标移动事件
/// </summary>
private void DragArea_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && ((UIElement)sender).IsMouseCaptured)
{
// 获取鼠标在屏幕上的当前位置
Point currentScreenPoint = this.PointToScreen(e.GetPosition(this));
Vector diff = currentScreenPoint - _dragStartPoint;

if (!_isDragging && (Math.Abs(diff.X) > 3 || Math.Abs(diff.Y) > 3))
{
_isDragging = true;
// 切换到绝对定位模式
this.HorizontalAlignment = HorizontalAlignment.Left;
this.VerticalAlignment = VerticalAlignment.Top;
}

if (_isDragging)
{
// 计算新位置
var parent = this.Parent as FrameworkElement;
if (parent != null)
{
// 计算屏幕坐标相对于父容器的位置
var parentPoint = parent.PointFromScreen(currentScreenPoint);
var startParentPoint = parent.PointFromScreen(_dragStartPoint);

// 计算相对于初始位置的偏移
double offsetX = parentPoint.X - startParentPoint.X;
double offsetY = parentPoint.Y - startParentPoint.Y;

// 新位置 = 初始位置 + 偏移
double newLeft = _controlStartPoint.X + offsetX;
double newTop = _controlStartPoint.Y + offsetY;

// 限制在父容器范围内
newLeft = Math.Max(0, Math.Min(newLeft, parent.ActualWidth - this.ActualWidth));
newTop = Math.Max(0, Math.Min(newTop, parent.ActualHeight - this.ActualHeight));

// 更新Margin
this.Margin = new Thickness(newLeft, newTop, 0, 0);
}
}
}
}

/// <summary>
/// 拖动区域鼠标释放事件
/// </summary>
private void DragArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (((UIElement)sender).IsMouseCaptured)
{
((UIElement)sender).ReleaseMouseCapture();
}

if (_isDragging)
{
Dispatcher.BeginInvoke(new Action(() => { _isDragging = false; }),
DispatcherPriority.Background);
}
else
{
_isDragging = false;
}

e.Handled = true;
}
}
}

39 changes: 37 additions & 2 deletions Ink Canvas/Helpers/CameraService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,16 @@ private void VideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
// 应用旋转
Bitmap rotatedFrame = ApplyRotation(sourceFrame);

// 应用分辨率调整
_currentFrame = ResizeImage(rotatedFrame, _resolutionWidth, _resolutionHeight);
int targetWidth = _resolutionWidth;
int targetHeight = _resolutionHeight;

if (_rotationAngle == 1 || _rotationAngle == 3)
{
targetWidth = _resolutionHeight;
targetHeight = _resolutionWidth;
}

_currentFrame = ResizeImageWithAspectRatio(rotatedFrame, targetWidth, targetHeight);

rotatedFrame?.Dispose();
}
Expand Down Expand Up @@ -357,6 +365,33 @@ private Bitmap ApplyRotation(Bitmap source)
return rotated;
}

/// <summary>
/// 调整图像大小
/// </summary>
private Bitmap ResizeImageWithAspectRatio(Bitmap source, int targetWidth, int targetHeight)
{
if (source.Width == targetWidth && source.Height == targetHeight)
return new Bitmap(source);

double scaleX = (double)targetWidth / source.Width;
double scaleY = (double)targetHeight / source.Height;
double scale = Math.Min(scaleX, scaleY);

// 计算实际尺寸
int actualWidth = (int)(source.Width * scale);
int actualHeight = (int)(source.Height * scale);

var resized = new Bitmap(actualWidth, actualHeight, PixelFormat.Format24bppRgb);
using (var graphics = Graphics.FromImage(resized))
{
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
graphics.DrawImage(source, 0, 0, actualWidth, actualHeight);
}
return resized;
}

/// <summary>
/// 调整图像大小
/// </summary>
Expand Down
Loading