Pārlūkot izejas kodu

词云蒙版支持

Suxue 1 gadu atpakaļ
vecāks
revīzija
cc63fe94a6
4 mainītis faili ar 18 papildinājumiem un 7 dzēšanām
  1. 14 6
      Pages/Workspace.xaml.cs
  2. 1 1
      README.md
  3. 3 0
      WechatBakTool.csproj
  4. BIN
      mask.png

+ 14 - 6
Pages/Workspace.xaml.cs

@@ -147,9 +147,13 @@ namespace WechatBakTool.Pages
                 {
                     if(UserReader != null && ViewModel.WXContact != null)
                     {
+                        System.Drawing.Image? mask = null;
+                        if (File.Exists("mask.png"))
+                            mask = System.Drawing.Image.FromFile("mask.png");
+
                         WordCloudSettingViewModel setting = new WordCloudSettingViewModel() {
-                            ImgWidth = "1000",
-                            ImgHeight = "1000",
+                            ImgWidth = mask == null ? "1000": mask.Width.ToString(),
+                            ImgHeight = mask == null ? "1000" : mask.Height.ToString(),
                             EnableRemoveOneKey = true,
                         };
                         Dispatcher.Invoke(() => {
@@ -190,15 +194,19 @@ namespace WechatBakTool.Pages
                         ViewModel.ExportCount = "渲染词云结果";
                         string resultPath = "result.jpg";
 
-                        var wordCloud = new WordCloud(int.Parse(setting.ImgWidth), int.Parse(setting.ImgHeight), allowVerical: true, fontname: setting.Font);
+                        WordCloud wordCloud;
+                        if(mask != null)
+                            wordCloud = new WordCloud(int.Parse(setting.ImgWidth), int.Parse(setting.ImgHeight), mask: mask, allowVerical: true, fontname: setting.Font);
+                        else
+                            wordCloud = new WordCloud(int.Parse(setting.ImgWidth), int.Parse(setting.ImgHeight), allowVerical: true, fontname: setting.Font);
 
-                        if(orderBy.Count() >= setting.MaxKeyCount)
+                        if (orderBy.Count() >= setting.MaxKeyCount)
                             orderBy = orderBy.Take(setting.MaxKeyCount);
-                        //var wordCloud = new WordCloud(1000, 1000,false, null,-1,1,null, false);
+
                         var result = wordCloud.Draw(orderBy.Select(it => it.Key).ToList(), orderBy.Select(it => it.Value).ToList());
                         result.Save(resultPath);
                         ViewModel.ExportCount = "完成";
-                        MessageBox.Show("生成完毕", "提示");
+                        MessageBox.Show("生成完毕,请查看软件根目录result.jpg", "提示");
                     }
                     return;
                 }

+ 1 - 1
README.md

@@ -40,8 +40,8 @@
 C# + .NET6.0 + WPF <br/>
 - [x] ~~新版本UI界面开发~~
 - [x] 完善各类消息支持(已经初步完成)
+- [x] ~~词云~~
 - [ ] 性能优化
-- [ ] 词云
 - [ ] 打包资源文件夹
 - [ ] 手动模式(合适离线分析)
 <br/>

+ 3 - 0
WechatBakTool.csproj

@@ -29,6 +29,9 @@
     <None Update="libssl-1_1.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
+    <None Update="mask.png">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Update="Resources\char_state_tab.json">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>

BIN
mask.png