Skip to content

Commit a99866d

Browse files
committed
新增自訂替換圖片功能
1 parent 7ac766c commit a99866d

File tree

8 files changed

+574
-113
lines changed

8 files changed

+574
-113
lines changed

作夥直排/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@
9595
<setting name="Batch_AddCustomizeCSS" serializeAs="String">
9696
<value>False</value>
9797
</setting>
98+
<setting name="Setting_UseBuiltinIMG" serializeAs="String">
99+
<value>True</value>
100+
</setting>
101+
<setting name="Setting_CustomizedIMGPath" serializeAs="String">
102+
<value />
103+
</setting>
98104
</ChoHoe.Properties.Settings>
99105
<作夥直排.Properties.Settings>
100106
<setting name="CalibrePath" serializeAs="String">

作夥直排/Book.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,28 @@ private void OpfWriter(bool PageDirection, bool Img, string Title, string Author
352352
}
353353
private void ImgReplace()
354354
{
355+
byte[] data;
356+
bool flag=false;
357+
try
358+
{
359+
System.Drawing.Image check = System.Drawing.Image.FromFile(ChoHoe.Properties.Settings.Default.Setting_CustomizedIMGPath);
360+
}
361+
catch (Exception)
362+
{
363+
DoLog.logger.Error("Can't load replacement img");
364+
flag = true;
365+
}
366+
System.Drawing.Image pic;
367+
if (flag||ChoHoe.Properties.Settings.Default.Setting_UseBuiltinIMG)
368+
{
369+
370+
pic = ChoHoe.Properties.Resources.Replacement_Image;
371+
}
372+
else
373+
{
374+
pic = System.Drawing.Image.FromFile(ChoHoe.Properties.Settings.Default.Setting_CustomizedIMGPath);
375+
}
376+
355377
if (imgpath["gif"].Count != 0)
356378
{
357379

@@ -361,11 +383,9 @@ private void ImgReplace()
361383

362384
{
363385
DoLog.logger.Info($"Replace gif: {path} ");
364-
byte[] data; //= System.Convert.FromBase64String(作夥直排.Properties.Resources.JpegReplacement);
365-
System.Drawing.Image gif = ChoHoe.Properties.Resources.Replacement_Image;
366386
using (MemoryStream ms = new MemoryStream())
367387
{
368-
gif.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
388+
pic.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
369389
data = ms.ToArray();
370390
}
371391
using (var imageFile = new FileStream(path, FileMode.Create))
@@ -382,11 +402,9 @@ private void ImgReplace()
382402
foreach (string path in imgpath["jpeg"])
383403
{
384404
DoLog.logger.Info($"Replace jpg: {path} ");
385-
byte[] data; //= System.Convert.FromBase64String(作夥直排.Properties.Resources.JpegReplacement);
386-
System.Drawing.Image jpg = ChoHoe.Properties.Resources.Replacement_Image;
387405
using (MemoryStream ms = new MemoryStream())
388406
{
389-
jpg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
407+
pic.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
390408
data = ms.ToArray();
391409
}
392410
using (var imageFile = new FileStream(path, FileMode.Create))
@@ -404,11 +422,9 @@ private void ImgReplace()
404422
foreach (string path in imgpath["png"])
405423
{
406424
DoLog.logger.Info($"Replace png: {path} ");
407-
byte[] data; //= System.Convert.FromBase64String(作夥直排.Properties.Resources.JpegReplacement);
408-
System.Drawing.Image png = ChoHoe.Properties.Resources.Replacement_Image;
409425
using (MemoryStream ms = new MemoryStream())
410426
{
411-
png.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
427+
pic.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
412428
data = ms.ToArray();
413429
}
414430
using (var imageFile = new FileStream(path, FileMode.Create))

作夥直排/Chehue.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
<Version>1.2.0</Version>
341341
</PackageReference>
342342
<PackageReference Include="HtmlAgilityPack">
343-
<Version>1.11.7</Version>
343+
<Version>1.11.49</Version>
344344
</PackageReference>
345345
<PackageReference Include="MetroFramework">
346346
<Version>1.2.0.3</Version>

作夥直排/Properties/Settings.Designer.cs

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

作夥直排/Properties/Settings.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,11 @@
8686
<Setting Name="Batch_AddCustomizeCSS" Type="System.Boolean" Scope="User">
8787
<Value Profile="(Default)">False</Value>
8888
</Setting>
89+
<Setting Name="Setting_UseBuiltinIMG" Type="System.Boolean" Scope="User">
90+
<Value Profile="(Default)">True</Value>
91+
</Setting>
92+
<Setting Name="Setting_CustomizedIMGPath" Type="System.String" Scope="User">
93+
<Value Profile="(Default)" />
94+
</Setting>
8995
</Settings>
9096
</SettingsFile>

作夥直排/Setting.Designer.cs

Lines changed: 44 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

作夥直排/Setting.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public Setting()
3131
linklbPacdoc.Text = ChoHoe.Properties.Settings.Default.PandocPath;
3232
LinkLBCalibrePath.Text = ChoHoe.Properties.Settings.Default.CalibrePath;
3333
LinkLBKinflegenPath.Text = ChoHoe.Properties.Settings.Default.KindlegenPath;
34+
35+
tgUseBuiltin.Checked = ChoHoe.Properties.Settings.Default.Setting_UseBuiltinIMG;
36+
ReloadImg();
37+
3438
}
3539

3640
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -193,5 +197,50 @@ private void metroButton5_Click(object sender, EventArgs e)
193197
{
194198
System.Diagnostics.Process.Start("https://kiicho.cc/Chohue/sidebar/manual.php?utm_source=Chehue&utm_medium=InApp&utm_campaign=InSetting_Plugin_epub&utm_content=manual_install_plugin#v-pills-install");
195199
}
200+
201+
private void tgUseBuiltin_CheckedChanged(object sender, EventArgs e)
202+
{
203+
204+
ChoHoe.Properties.Settings.Default.Setting_UseBuiltinIMG = tgUseBuiltin.Checked;
205+
ChoHoe.Properties.Settings.Default.Save();
206+
ReloadImg();
207+
208+
209+
}
210+
211+
private void btnLoadIMG_Click(object sender, EventArgs e)
212+
{
213+
OpenFileDialog openFile = new OpenFileDialog();
214+
openFile.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.gif;*.tif;*.bmp;";
215+
if (openFile.ShowDialog()==DialogResult.OK)
216+
{
217+
string path=openFile.FileName;
218+
219+
ChoHoe.Properties.Settings.Default.Setting_CustomizedIMGPath = path;
220+
ChoHoe.Properties.Settings.Default.Save();
221+
ReloadImg();
222+
223+
}
224+
}
225+
private void ReloadImg()
226+
{
227+
lbReplaceIMG.Text = Path.GetFileName(ChoHoe.Properties.Settings.Default.Setting_CustomizedIMGPath);
228+
try
229+
{
230+
if (!tgUseBuiltin.Checked)
231+
{
232+
pb_ReplaceIMG.Load(ChoHoe.Properties.Settings.Default.Setting_CustomizedIMGPath);
233+
}
234+
else
235+
{
236+
pb_ReplaceIMG.Image = ChoHoe.Properties.Resources.Replacement_Image;
237+
}
238+
}
239+
catch (Exception)
240+
{
241+
242+
DoLog.logger.Error("Can't load replacement img");
243+
}
244+
}
196245
}
197246
}

0 commit comments

Comments
 (0)