fasdfsa commited on
Commit
df39c73
·
1 Parent(s): 279340c

fix 点图片名出拆解文本

Browse files
Files changed (1) hide show
  1. src/WpfEditor/MainWindow.xaml.cs +65 -78
src/WpfEditor/MainWindow.xaml.cs CHANGED
@@ -1002,6 +1002,13 @@ namespace WpfEditor
1002
  }
1003
 
1004
  }
 
 
 
 
 
 
 
1005
  }
1006
  }
1007
 
@@ -2765,109 +2772,89 @@ namespace WpfEditor
2765
  On_Rectangle_adjust(rectangle);
2766
  }
2767
 
2768
- // 树形目录选择变化事件
2769
- private async void DirectoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
2770
  {
2771
- if (e.NewValue is DirectoryTreeNode selectedNode)
2772
  {
2773
- string ImageMD5 = "";
2774
-
2775
- foreach (TextCharacter c in selectedNode.line.Characters)
2776
- {
2777
- if (c.ImageMD5 != "")
2778
- {
2779
- ImageMD5 = c.ImageMD5;
2780
- break;
2781
- }
2782
- }
2783
 
2784
- if (ImageMD5 != "")
2785
- {
2786
 
2787
- //_pthimg
2788
 
2789
- // 要先找出真实图片名
 
 
 
2790
 
2791
- if (!_dic_m5_imgname.ContainsKey(ImageMD5))
2792
- {
2793
- throw new Exception("Error: somthing wrong.");
2794
- }
2795
 
2796
- string image_pth = _dic_m5_imgname[ImageMD5];
2797
 
2798
- this._currentFilePath = image_pth;
2799
 
2800
- //string pth_ = this._currentFilePath;
 
 
2801
 
2802
- //string dir = Path.GetDirectoryName(image_pth);
2803
 
2804
- //string pth_json = Path.Combine([dir, "json", $"{ImageMD5}.json"]);
2805
- //string pth_img = Path.Combine([dir, "img", $"{ImageMD5}.txt"]);
 
 
 
 
 
2806
 
2807
- //if (!Path.Exists(pth_json) || !Path.Exists(pth_img))
2808
- //{
2809
- // throw new Exception($"{ImageMD5} json or img not found.");
2810
- //}
2811
 
 
 
 
2812
 
2813
- //var jsonstr = File.ReadAllText(pth_json, new System.Text.UTF8Encoding(false));
 
 
 
 
 
 
2814
 
2815
- //JObject jsn = null;
2816
- //try
2817
- //{
2818
- // jsn = JObject.Parse(jsonstr);
2819
- //}
2820
- //catch (Exception ex)
2821
- //{
2822
- // MessageBox.Show("json 解析失败", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
2823
- //}
2824
 
2825
- //pth_json = Path.GetFullPath(pth_json);
 
 
2826
 
2827
- var (jsn, m5, pth_img, pth_json) = await Global.img_md5_jsn(image_pth, _ocrMode);
2828
 
2829
- if (Path.Exists(pth_json))
2830
- {
2831
- Editor._lines.Clear();
2832
 
2833
- Editor._lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json);
2834
 
2835
- Editor._undoBuffer.Clear();
2836
- Editor._undoIndex = -1;
2837
- Editor._cursorLine = 0;
2838
- Editor._cursorColumn = 0;
2839
- Editor.ClearSelection();
2840
- Editor._textChanged = true;
2841
- Editor.InvalidateVisual();
2842
 
2843
- // 触发文本改变事件
2844
- Editor.OnTextChanged();
 
 
 
 
2845
 
2846
- UpdateTitle();
2847
- StatusText.Text = $"已打开: {_currentFilePath}";
 
 
 
 
2848
  }
2849
-
2850
- // 加载原图
2851
- string b64_str = File.ReadAllText(pth_img, Encoding.UTF8);
2852
- byte[] img_bytes = Base64.Base64Decode(b64_str);
2853
- Mat im_orig = Cv2.ImDecode(img_bytes, ImreadModes.Color);
2854
- BitmapSource source = TextEditorControl.MatToBitmapSource(im_orig);
2855
- ViewModel.Image = source;
2856
- ViewModel.ClearAllRectangles();
2857
-
2858
-
2859
- // 重置图片尺寸记录
2860
- _previousImageWidth = 0;
2861
- _previousImageHeight = 0;
2862
-
2863
-
2864
- Editor._pthimg = image_pth;
2865
- Editor._jsn_OpenImg = jsn;
2866
- Editor._md5_OpenImg = ImageMD5;
2867
-
2868
  }
2869
 
2870
-
 
 
 
2871
  }
2872
  }
2873
  }
 
1002
  }
1003
 
1004
  }
1005
+ else if (this._mode == EditorMode.MenuSplit)
1006
+ {
1007
+ if (m5 != "")
1008
+ {
1009
+ await split_menu_openImage(m5);
1010
+ }
1011
+ }
1012
  }
1013
  }
1014
 
 
2772
  On_Rectangle_adjust(rectangle);
2773
  }
2774
 
2775
+ private async Task split_menu_openImage(string ImageMD5)
 
2776
  {
2777
+ if (ImageMD5 != "")
2778
  {
 
 
 
 
 
 
 
 
 
 
2779
 
2780
+ //_pthimg
 
2781
 
2782
+ // 要先找出真实图片名
2783
 
2784
+ if (!_dic_m5_imgname.ContainsKey(ImageMD5))
2785
+ {
2786
+ throw new Exception("Error: somthing wrong.");
2787
+ }
2788
 
2789
+ string image_pth = _dic_m5_imgname[ImageMD5];
 
 
 
2790
 
2791
+ this._currentFilePath = image_pth;
2792
 
2793
+ var (jsn, m5, pth_img, pth_json) = await Global.img_md5_jsn(image_pth, _ocrMode);
2794
 
2795
+ if (Path.Exists(pth_json))
2796
+ {
2797
+ Editor._lines.Clear();
2798
 
2799
+ Editor._lines = Global.loadJsonReviseEdit_FromOriginalPath(pth_json);
2800
 
2801
+ Editor._undoBuffer.Clear();
2802
+ Editor._undoIndex = -1;
2803
+ Editor._cursorLine = 0;
2804
+ Editor._cursorColumn = 0;
2805
+ Editor.ClearSelection();
2806
+ Editor._textChanged = true;
2807
+ Editor.InvalidateVisual();
2808
 
2809
+ // 触发文本改变事件
2810
+ Editor.OnTextChanged();
 
 
2811
 
2812
+ UpdateTitle();
2813
+ StatusText.Text = $"已打开: {_currentFilePath}";
2814
+ }
2815
 
2816
+ // 加载原图
2817
+ string b64_str = File.ReadAllText(pth_img, Encoding.UTF8);
2818
+ byte[] img_bytes = Base64.Base64Decode(b64_str);
2819
+ Mat im_orig = Cv2.ImDecode(img_bytes, ImreadModes.Color);
2820
+ BitmapSource source = TextEditorControl.MatToBitmapSource(im_orig);
2821
+ ViewModel.Image = source;
2822
+ ViewModel.ClearAllRectangles();
2823
 
 
 
 
 
 
 
 
 
 
2824
 
2825
+ // 重置图片尺寸记录
2826
+ _previousImageWidth = 0;
2827
+ _previousImageHeight = 0;
2828
 
 
2829
 
2830
+ Editor._pthimg = image_pth;
2831
+ Editor._jsn_OpenImg = jsn;
2832
+ Editor._md5_OpenImg = ImageMD5;
2833
 
2834
+ }
2835
 
2836
+ }
 
 
 
 
 
 
2837
 
2838
+ // 树形目录选择变化事件
2839
+ private async void DirectoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
2840
+ {
2841
+ if (e.NewValue is DirectoryTreeNode selectedNode)
2842
+ {
2843
+ string ImageMD5 = "";
2844
 
2845
+ foreach (TextCharacter c in selectedNode.line.Characters)
2846
+ {
2847
+ if (c.ImageMD5 != "")
2848
+ {
2849
+ ImageMD5 = c.ImageMD5;
2850
+ break;
2851
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2852
  }
2853
 
2854
+ if (ImageMD5 != "")
2855
+ {
2856
+ await split_menu_openImage(ImageMD5);
2857
+ }
2858
  }
2859
  }
2860
  }