feat: add screenshot translate

dev_ocr_translate
DESKTOP-3BO4HSG\ksat 2 years ago
parent feef0e3d8b
commit 1ac7c152e2

@ -279,7 +279,7 @@ namespace STranslate.Util
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
brush.ImageSource = wpfBitmap;
//TODO: flush Memory
FlushMemory();
return brush;
}
/// <summary>

@ -11,13 +11,13 @@ namespace STranslate.View
/// </summary>
public partial class MainWindow : Window
{
private MainVM vm;
private MainVM vm = MainVM.Instance;
public MainWindow()
{
//InitializeComponent();
DataContext = new MainVM(this);
vm = (MainVM)DataContext;
DataContext = vm;
vm.Mainwin = this;
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{

@ -40,9 +40,9 @@
</i:Interaction.Triggers>
<Canvas x:Name="ScreenCanvas">
<Rectangle x:Name="LeftMask" Fill="#111410" Opacity="0.6" />
<Rectangle x:Name="RightMask" Fill="#111410" Opacity="0.6" />
<Rectangle x:Name="UpMask" Fill="#111410" Opacity="0.6" />
<Rectangle x:Name="DownMask" Fill="#111410" Opacity="0.6" />
<Rectangle x:Name="LeftMask" Fill="#7f7f7f" Opacity="0.6" />
<Rectangle x:Name="RightMask" Fill="#7f7f7f" Opacity="0.6" />
<Rectangle x:Name="UpMask" Fill="#7f7f7f" Opacity="0.6" />
<Rectangle x:Name="DownMask" Fill="#7f7f7f" Opacity="0.6" />
</Canvas>
</Window>

@ -14,11 +14,8 @@ namespace STranslate.ViewModel
{
public class MainVM : BaseVM
{
public MainVM(Window win)
public MainVM()
{
_Mainwin = (MainWindow)win;
if (!ReadConfig())
{
ExitApp(-1);
@ -68,12 +65,12 @@ namespace STranslate.ViewModel
{
if (IsTopmost)
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
(Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _UnTopmostTemplateName);
}
else
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
(Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _TopmostTemplateName);
}
IsTopmost = !IsTopmost;
@ -82,12 +79,12 @@ namespace STranslate.ViewModel
//ESC
EscCmd = new RelayCommand((_) => true, (_) =>
{
_Mainwin.Hide();
Mainwin.Hide();
//取消置顶
if (IsTopmost)
{
(_Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
(Mainwin.FindName("TopmostBtn") as System.Windows.Controls.Button)
.SetResourceReference(System.Windows.Controls.Control.TemplateProperty, _UnTopmostTemplateName);
IsTopmost = !IsTopmost;
}
@ -109,7 +106,7 @@ namespace STranslate.ViewModel
//移动
MouseLeftDownCmd = new RelayCommand((_) => true, (_) =>
{
_Mainwin.DragMove();
Mainwin.DragMove();
});
//失去焦点
DeactivatedCmd = new RelayCommand((_) => true, (_) =>
@ -117,7 +114,7 @@ namespace STranslate.ViewModel
if (!IsTopmost)
{
Speech.SpeakAsyncCancelAll();
_Mainwin.Hide();
Mainwin.Hide();
}
});
//source speak
@ -194,9 +191,9 @@ namespace STranslate.ViewModel
/// </summary>
public void OpenMainWin()
{
_Mainwin.Show();
_Mainwin.Activate();
(_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus();
Mainwin.Show();
Mainwin.Activate();
(Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Focus();
}
/// <summary>
/// 输入翻译
@ -214,7 +211,7 @@ namespace STranslate.ViewModel
ClearAll();
var sentence = GetWordsHelper.Get();
OpenMainWin();
(_Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox)
(Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox)
.Text = sentence.Trim();
_ = Translate();
}
@ -223,10 +220,18 @@ namespace STranslate.ViewModel
/// </summary>
public void ScreenShotTranslate()
{
//MessageBox.Show("aaa");
var xx = new ScreenShotWindow();
xx.Show();
xx.Activate();
var screen = new ScreenShotWindow();
screen.Show();
screen.Activate();
}
/// <summary>
/// 截屏翻译Ex
/// </summary>
public void ScreenShotTranslateEx(string text)
{
InputTranslate();
(Mainwin.FindName("TextBoxInput") as System.Windows.Controls.TextBox).Text = text;
_ = Translate();
}
/// <summary>
@ -434,10 +439,20 @@ namespace STranslate.ViewModel
/// </summary>
private bool _IsStartup;
public bool IsStartup { get => _IsStartup; set => UpdateProperty(ref _IsStartup, value); }
/// <summary>
/// 托盘图标可见
/// </summary>
private bool _IsVisibility = true;
public bool IsVisibility { get => _IsVisibility; set => UpdateProperty(ref _IsVisibility, value); }
private MainWindow _Mainwin;
/// <summary>
/// view传递至viewmodel
/// </summary>
public MainWindow Mainwin;
private static MainVM _Instance;
public static MainVM Instance => _Instance ?? (_Instance = new MainVM());
public bool IsTopmost { get; set; }
private readonly string _TopmostTemplateName = "ButtonTemplateTopmost";
private readonly string _UnTopmostTemplateName = "ButtonTemplateUnTopmost";

@ -86,9 +86,9 @@ namespace STranslate.ViewModel
//TestSaveBmp(bmpOut);
var xx = Util.Util.TesseractGetText(bmpOut).Trim();
MessageBox.Show(xx);
System.Diagnostics.Debug.Print(xx);
var getText = Util.Util.TesseractGetText(bmpOut).Trim();
MainVM.Instance.ScreenShotTranslateEx(getText);
});
ClosedCmd = new RelayCommand((_) => true, (_) =>

Loading…
Cancel
Save