Skip to content

Commit

Permalink
v0.3.0 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
GarthTB committed Nov 26, 2024
1 parent 3c38fca commit 8937703
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion FrameMark/Components/Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static void Show()
.ToString()
?? "未知";
var sb = new StringBuilder();
var help = sb.AppendLine("欢迎使用图片加边框水印工具\n")
var help = sb.AppendLine("欢迎使用图片边框与水印工具\n")
.AppendLine("本程序会对照片进行以下操作:")
.AppendLine("1. 按需要放大、模糊,并压暗,作为边框。\n 模糊半径为图像长边的指定百分比。")
.AppendLine("2. 将图片本身切去圆角,放在其上。\n 圆角半径为图像短边的指定百分比。")
Expand Down
32 changes: 22 additions & 10 deletions FrameMark/Components/ImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,47 @@ internal void Run()
private static string AggregateInfo(MagickImage image, string shutter, string apertrue, string iso, string focalLen)
{
var exif = image.GetExifProfile();
var s = exif?.GetValue(ExifTag.ExposureTime)?.Value.ToString() ?? shutter;
var s = Normalize(exif?.GetValue(ExifTag.ExposureTime)?.Value.ToString()) ?? shutter;
var a = ConvertFraction(exif?.GetValue(ExifTag.FNumber)?.Value.ToString()) ?? apertrue;
var i = exif?.GetValue(ExifTag.ISOSpeed)?.Value.ToString() ?? iso;
var f = exif?.GetValue(ExifTag.FocalLengthIn35mmFilm)?.ToString()
?? ConvertFraction(exif?.GetValue(ExifTag.FocalLength)?.Value.ToString())
?? focalLen;

List<string> info = new(4);
if (s.Length > 0) info.Add($"{s}s");
if (s.Length > 0) info.Add($"{s} s");
if (a.Length > 0) info.Add($"f/{a}");
if (i.Length > 0) info.Add($"ISO {i}");
if (f.Length > 0) info.Add($"{f}mm");
if (f.Length > 0) info.Add($"{f} mm");
return info.Aggregate((a, b) => $"{a} | {b}");

static string? Normalize(string? value)
{
if (value == null) return null;
var parts = value.Split('/');
return parts.Length != 2
|| parts[0] == "1"
|| !uint.TryParse(parts[0], out var up)
|| !uint.TryParse(parts[1], out var down)
? value // 如果不为分数或者已通分,则原样返回
: up > down
? $"{(double)up / down:#.#}"
: $"1/{(double)down / up:#.#}";
}

static string? ConvertFraction(string? value)
{
if (value == null) return null;
var parts = value.Split('/');
if (parts.Length != 2
|| !uint.TryParse(parts[0], out var up)
|| !uint.TryParse(parts[1], out var down)) return value;
if (up > down)
if (up > down) // 如果分子大,则直接插入小数点
{
var accuracy = parts[1].Length - 1;
var upLen = parts[0].Length;
var dotIndex = upLen - accuracy;
var dotIndex = parts[0].Length - parts[1].Length + 1;
return $"{parts[0][..dotIndex]}.{parts[0][dotIndex..]}";
}
else
else // 如果分母大,则按精度保留指定长度
{
var result = (double)up / down;
return result.ToString()[..(parts[1].Length + 1)];
Expand Down Expand Up @@ -134,8 +146,8 @@ private static IMagickImage GenerateWatermark(MagickImage image, IMagickImage bk
bkg.Composite(wm, (int)xOffset, (int)yOffset, CompositeOperator.Over);
var drawables = new Drawables().FillColor(new MagickColor(62720, 62720, 62720))
.FontPointSize(fontPoint)
.StrokeColor(new MagickColor(2560, 2560, 2560))
.StrokeWidth(fontPoint * 0.025)
.StrokeColor(new MagickColor(60000, 60000, 60000))
.StrokeWidth(fontPoint * 0.008)
.Text(xOffset + wmWidth + textHeight * 0.618, yOffset + textHeight * 0.8, text);
_ = drawables.Draw((IMagickImage<float>)bkg);
return bkg;
Expand Down
2 changes: 1 addition & 1 deletion FrameMark/FrameMark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageId>FrameMark</PackageId>
<Title>FrameMark</Title>
<Product>FrameMark</Product>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
<Authors>GarthTB</Authors>
<Company>GarthTB</Company>
<Copyright>© GarthTB 2024</Copyright>
Expand Down
2 changes: 1 addition & 1 deletion FrameMark/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
FontSize="16"
KeyDown="MW_KeyDown"
SizeToContent="WidthAndHeight"
Title="边框和水印工具">
Title="边框与水印工具">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="225" />
Expand Down
2 changes: 2 additions & 0 deletions FrameMark/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void BtRemoveFile_Click(object sender, RoutedEventArgs e)

private void BtRun_Click(object sender, RoutedEventArgs e)
{
MW.Title = "边框与水印工具 处理中,请等待...";
Components.ImageEditor editor = new(
double.Parse(TBFrameT.Text),
double.Parse(TBFrameB.Text),
Expand All @@ -136,6 +137,7 @@ private void BtRun_Click(object sender, RoutedEventArgs e)
LBFiles.Items.Cast<string>().ToArray()
);
editor.Run();
MW.Title = "边框与水印工具";
}

#endregion
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@

- F1:帮助

## Credits

- [Magick.NET](https://github.com/dlemstra/Magick.NET)

# 版本日志

## [0.3.0] - 2024-11-26

- 修复:某些照片的快门参数没有通分的问题
- 改进:优化参数字体
- 改进:完善提示

## [0.2.0] - 2024-11-25

- 修复:照片不能不等比缩放的问题
Expand Down

0 comments on commit 8937703

Please sign in to comment.