Skip to content

Commit

Permalink
优化UI、优化预览图生成速度
Browse files Browse the repository at this point in the history
  • Loading branch information
liesauer committed Apr 8, 2022
1 parent 3206e0e commit 9876494
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
4 changes: 4 additions & 0 deletions pic2meme/ChangeLogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public ChangeLogWindow()
this.MinWidth = this.MaxWidth = this.Width;
this.MinHeight = this.MaxHeight = this.Height;
ChangeLog.Text = @"
v1.2.2 - 2022/04/08
1. 优化UI
2. 优化预览图生成速度
v1.2.1 - 2022/04/08
1. 修复无法直接转换QQ图片的问题
Expand Down
18 changes: 10 additions & 8 deletions pic2meme/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:pic2meme" xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Title="微信表情包工具 v1.2.1" Height="499.632" Width="463.297" AllowDrop="True" Drop="Window_Drop" KeyDown="Window_KeyDown" ResizeMode="CanMinimize">
Title="微信表情包工具 v1.2.2" Height="535.632" Width="538.297" AllowDrop="True" Drop="Window_Drop" KeyDown="Window_KeyDown" ResizeMode="CanMinimize">
<Grid>
<Label x:Name="Notice" Content="拖动或粘贴图片到此处进行表情包转换" FontSize="22" Margin="30,20,0,0" VerticalAlignment="Top" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" Width="395" />
<hc:GifImage x:Name="Preview" Stretch="Uniform" Height="201" Margin="127,144,0,126" HorizontalAlignment="Left" Width="201" />
<Label x:Name="Notice" Content="拖动或粘贴图片到此处进行表情包转换" FontSize="22" Margin="30,20,30,0" VerticalAlignment="Top" Height="54" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Stretch" />
<hc:GifImage x:Name="Preview" Stretch="Uniform" Height="200" Width="200" Margin="128,151,129.5,127.5" />


<Button x:Name="Usage" Content="使用说明" HorizontalAlignment="Left" Margin="30,0,0,27" VerticalAlignment="Bottom" Width="116" Height="52" FontSize="20" Click="Usage_Click" FocusVisualStyle="{x:Null}" />
<Button x:Name="ChangeLog" Content="更新历史" HorizontalAlignment="Left" Margin="170,0,0,27" VerticalAlignment="Bottom" Width="116" Height="52" FontSize="20" Click="ChangeLog_Click" FocusVisualStyle="{x:Null}" />
<Button x:Name="BuyMyACoffee" Content="支持一下" HorizontalAlignment="Left" Margin="310,0,0,27" VerticalAlignment="Bottom" Height="52" FontSize="20" Click="BuyMyACoffee_Click" FocusVisualStyle="{x:Null}" Width="116" />
<RadioButton x:Name="CovertMode1" Content="模式1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,94,0,0" Height="38" Width="85" FontSize="20" GroupName="CovertMode" IsChecked="True" Checked="CovertMode1_Checked" FocusVisualStyle="{x:Null}" />
<RadioButton x:Name="CovertMode2" Content="模式2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="340,94,0,0" Height="38" Width="85" FontSize="20" GroupName="CovertMode" Checked="CovertMode2_Checked" FocusVisualStyle="{x:Null}" />
<Label x:Name="PreviewLabel" Content="" HorizontalAlignment="Left" Margin="128,225,0,0" VerticalAlignment="Top" BorderThickness="0" FontSize="22" Width="200" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
<Button x:Name="ChangeLog" Content="更新历史" HorizontalAlignment="Left" Margin="207,0,0,27" VerticalAlignment="Bottom" Width="116" Height="52" FontSize="20" Click="ChangeLog_Click" FocusVisualStyle="{x:Null}" />
<Button x:Name="BuyMyACoffee" Content="支持一下" HorizontalAlignment="Stretch" Margin="386,0,30.5,27" VerticalAlignment="Bottom" Height="52" FontSize="20" Click="BuyMyACoffee_Click" FocusVisualStyle="{x:Null}" />
<RadioButton x:Name="CovertMode1" Content="模式1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="80,94,0,0" Height="38" Width="85" FontSize="20" GroupName="CovertMode" IsChecked="True" Checked="CovertMode1_Checked" FocusVisualStyle="{x:Null}" />
<RadioButton x:Name="CovertMode2" Content="模式2" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,94,70.5,0" Height="38" FontSize="20" GroupName="CovertMode" Checked="CovertMode2_Checked" FocusVisualStyle="{x:Null}" Width="85" />
<Label x:Name="PreviewLabel" Content="" Margin="166,240,166.5,217" BorderThickness="0" FontSize="18" Width="200" Height="50" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
</Grid>
</Window>
27 changes: 5 additions & 22 deletions pic2meme/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ private async void pic2meme()
}

var tmpImage = GenerateTempFile(".gif");
var tmpPrevImage = GenerateTempFile(".gif");

Task<bool> covertTask = null;
Task<bool> previewTask = null;

try
{
Expand Down Expand Up @@ -213,26 +211,16 @@ private async void pic2meme()
return;
}
}
if (covertMode == 1)
{
previewTask = Utils.Any2GIF(sourceImage, tmpPrevImage, 200);
}
else if (covertMode == 2)
{
previewTask = Utils.Any2GIF(sourceImage, tmpPrevImage, 200);
}
}
else
{
if (covertMode == 1)
{
covertTask = Utils.Any2GIF(sourceImage, tmpImage);
previewTask = Utils.Any2GIF(sourceImage, tmpPrevImage, 200);
}
else if (covertMode == 2)
{
covertTask = Utils.Any2GIF2(sourceImage, tmpImage);
previewTask = Utils.Any2GIF(sourceImage, tmpPrevImage, 200);
}
}
}
Expand All @@ -256,16 +244,8 @@ private async void pic2meme()
Notice.Content = "转换成功,直接粘贴到微信发送即可";
SetImageToClipboard(tmpImage);

if (previewTask != null)
{
PreviewLabel.Content = "预览图生成中...";
_ = previewTask.ContinueWith(_ =>
{
this.PreviewLabel.Dispatcher.Invoke(() => {
SetPreview(tmpPrevImage);
});
});
}
PreviewLabel.Content = "预览图生成中...";
SetPreview(tmpImage);
}

private string SaveBitmapSource(BitmapSource source)
Expand Down Expand Up @@ -310,6 +290,9 @@ private void SetPreview(string imageFile)
PreviewLabel.Visibility = Visibility.Hidden;
PreviewLabel.Content = "";
Preview.Uri = new Uri(@"pack://siteoforigin:,,,/" + imageFile.Replace(@"\", @"/"));
var size = Utils.GetImageSize(imageFile);
Preview.MaxWidth = size.width;
Preview.MaxHeight = size.height;
}
catch (Exception)
{
Expand Down

0 comments on commit 9876494

Please sign in to comment.