improve:插入图片
This commit is contained in:
@@ -765,6 +765,12 @@
|
|||||||
FontFamily="Microsoft YaHei UI" FontWeight="Bold"
|
FontFamily="Microsoft YaHei UI" FontWeight="Bold"
|
||||||
Toggled="ToggleSwitchClearCanvasAndClearTimeMachine_Toggled" />
|
Toggled="ToggleSwitchClearCanvasAndClearTimeMachine_Toggled" />
|
||||||
</ui:SimpleStackPanel>
|
</ui:SimpleStackPanel>
|
||||||
|
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
|
<TextBlock Foreground="#fafafa" Text="插入图片时自动压缩(大于1920x1080)" VerticalAlignment="Center" FontSize="14" Margin="0,0,16,0" />
|
||||||
|
<ui:ToggleSwitch OnContent="" OffContent="" Name="ToggleSwitchCompressPicturesUploaded"
|
||||||
|
IsOn="True" FontFamily="Microsoft YaHei UI" FontWeight="Bold"
|
||||||
|
Toggled="ToggleSwitchCompressPicturesUploaded_Toggled" />
|
||||||
|
</ui:SimpleStackPanel>
|
||||||
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
||||||
StrokeThickness="1" Margin="0,4,0,4" />
|
StrokeThickness="1" Margin="0,4,0,4" />
|
||||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using System.Text;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using Image = System.Windows.Controls.Image;
|
||||||
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
||||||
|
|
||||||
namespace Ink_Canvas {
|
namespace Ink_Canvas {
|
||||||
@@ -1989,7 +1990,65 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建并压缩图片的异步方法
|
||||||
|
/// </summary>
|
||||||
|
private async Task<Image> CreateAndCompressImageAsync(string filePath)
|
||||||
|
{
|
||||||
|
string savePath = System.IO.Path.Combine(Settings.Automation.AutoSavedStrokesLocation, "File Dependency");
|
||||||
|
if (!System.IO.Directory.Exists(savePath))
|
||||||
|
System.IO.Directory.CreateDirectory(savePath);
|
||||||
|
|
||||||
|
string fileExtension = System.IO.Path.GetExtension(filePath);
|
||||||
|
string timestamp = "img_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss_fff");
|
||||||
|
string newFilePath = System.IO.Path.Combine(savePath, timestamp + fileExtension);
|
||||||
|
|
||||||
|
await Task.Run(() => System.IO.File.Copy(filePath, newFilePath, true));
|
||||||
|
|
||||||
|
return await Dispatcher.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
var bitmapImage = new BitmapImage();
|
||||||
|
bitmapImage.BeginInit();
|
||||||
|
bitmapImage.UriSource = new Uri(newFilePath);
|
||||||
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bitmapImage.EndInit();
|
||||||
|
|
||||||
|
int width = bitmapImage.PixelWidth;
|
||||||
|
int height = bitmapImage.PixelHeight;
|
||||||
|
|
||||||
|
Image image = new Image();
|
||||||
|
if (Settings.Canvas.IsCompressPicturesUploaded && (width > 1920 || height > 1080))
|
||||||
|
{
|
||||||
|
double scaleX = 1920.0 / width;
|
||||||
|
double scaleY = 1080.0 / height;
|
||||||
|
double scale = Math.Min(scaleX, scaleY);
|
||||||
|
var transformedBitmap = new TransformedBitmap(bitmapImage, new ScaleTransform(scale, scale));
|
||||||
|
image.Source = transformedBitmap;
|
||||||
|
image.Width = transformedBitmap.PixelWidth;
|
||||||
|
image.Height = transformedBitmap.PixelHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
image.Source = bitmapImage;
|
||||||
|
image.Width = width;
|
||||||
|
image.Height = height;
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void InsertImage_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new Microsoft.Win32.OpenFileDialog
|
||||||
|
{
|
||||||
|
Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp;*.gif"
|
||||||
|
};
|
||||||
|
if (dialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
var image = await CreateAndCompressImageAsync(dialog.FileName);
|
||||||
|
// TODO: 这里可以将image添加到画布或其他控件
|
||||||
|
MessageBox.Show("图片已处理完成,可在此处插入到画布。");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2165,5 +2165,12 @@ namespace Ink_Canvas {
|
|||||||
Settings.PowerPointSettings.EnableWppProcessKill = ToggleSwitchEnableWppProcessKill.IsOn;
|
Settings.PowerPointSettings.EnableWppProcessKill = ToggleSwitchEnableWppProcessKill.IsOn;
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ToggleSwitchCompressPicturesUploaded_Toggled(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!isLoaded) return;
|
||||||
|
Settings.Canvas.IsCompressPicturesUploaded = ToggleSwitchCompressPicturesUploaded.IsOn;
|
||||||
|
SaveSettingsToFile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -549,6 +549,7 @@ namespace Ink_Canvas {
|
|||||||
|
|
||||||
// 初始化直线端点吸附相关设置
|
// 初始化直线端点吸附相关设置
|
||||||
ToggleSwitchLineEndpointSnapping.IsOn = Settings.Canvas.LineEndpointSnapping;
|
ToggleSwitchLineEndpointSnapping.IsOn = Settings.Canvas.LineEndpointSnapping;
|
||||||
|
ToggleSwitchCompressPicturesUploaded.IsOn = Settings.Canvas.IsCompressPicturesUploaded;
|
||||||
} else {
|
} else {
|
||||||
Settings.Canvas = new Canvas();
|
Settings.Canvas = new Canvas();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ namespace Ink_Canvas
|
|||||||
|
|
||||||
[JsonProperty("hyperbolaAsymptoteOption")]
|
[JsonProperty("hyperbolaAsymptoteOption")]
|
||||||
public OptionalOperation HyperbolaAsymptoteOption { get; set; } = OptionalOperation.Ask;
|
public OptionalOperation HyperbolaAsymptoteOption { get; set; } = OptionalOperation.Ask;
|
||||||
|
[JsonProperty("isCompressPicturesUploaded")]
|
||||||
|
public bool IsCompressPicturesUploaded { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OptionalOperation
|
public enum OptionalOperation
|
||||||
|
|||||||
Reference in New Issue
Block a user