|
@@ -23,6 +23,8 @@ using System.Windows.Ink;
|
|
|
using ComPDFKitViewer;
|
|
|
using System.Net.NetworkInformation;
|
|
|
using compdfkit_tools.Common;
|
|
|
+using static System.Net.Mime.MediaTypeNames;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
|
|
|
namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
|
|
|
{
|
|
@@ -106,30 +108,37 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
|
|
|
string name = Guid.NewGuid().ToString();
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
{
|
|
|
- BitmapImage image = new BitmapImage(new Uri(FilePath));
|
|
|
- double scale = Math.Min((double)600 / image.PixelWidth, (double)600 / image.PixelHeight);
|
|
|
- scale = Math.Min(scale, 1);
|
|
|
- BitmapEncoder encoder = new PngBitmapEncoder();
|
|
|
- var targetBitmap = new TransformedBitmap(image, new ScaleTransform(scale, scale));
|
|
|
- encoder.Frames.Add(BitmapFrame.Create(targetBitmap));
|
|
|
- path = System.IO.Path.Combine(path, name);
|
|
|
- using (FileStream stream = new FileStream(path, FileMode.Create))
|
|
|
+ try
|
|
|
{
|
|
|
- encoder.Save(stream);
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty(SaveToPath))
|
|
|
- {
|
|
|
- DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
|
|
|
- if (CreatedFilePathFolder.Exists)
|
|
|
+ BitmapImage image = new BitmapImage(new Uri(FilePath));
|
|
|
+ double scale = Math.Min((double)600 / image.PixelWidth, (double)600 / image.PixelHeight);
|
|
|
+ scale = Math.Min(scale, 1);
|
|
|
+ BitmapEncoder encoder = new PngBitmapEncoder();
|
|
|
+ var targetBitmap = new TransformedBitmap(image, new ScaleTransform(scale, scale));
|
|
|
+ encoder.Frames.Add(BitmapFrame.Create(targetBitmap));
|
|
|
+ path = System.IO.Path.Combine(path, name);
|
|
|
+ using (FileStream stream = new FileStream(path, FileMode.Create))
|
|
|
{
|
|
|
- Directory.Delete(SaveToPath, true);
|
|
|
+ encoder.Save(stream);
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(SaveToPath))
|
|
|
+ {
|
|
|
+ DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
|
|
|
+ if (CreatedFilePathFolder.Exists)
|
|
|
+ {
|
|
|
+ Directory.Delete(SaveToPath, true);
|
|
|
+ }
|
|
|
}
|
|
|
+ SaveToPath = path;
|
|
|
+
|
|
|
+ AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
+ ImageImage.Source = targetBitmap;
|
|
|
+ SaveBtn.IsEnabled = true;
|
|
|
}
|
|
|
- SaveToPath = path;
|
|
|
+ catch
|
|
|
+ {
|
|
|
|
|
|
- AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
- ImageImage.Source = targetBitmap;
|
|
|
- SaveBtn.IsEnabled = true;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -430,5 +439,23 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
|
|
|
{
|
|
|
TextColorPickerControl.SetIsChecked(1);
|
|
|
}
|
|
|
+
|
|
|
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty((sender as TextBox).Text))
|
|
|
+ {
|
|
|
+ int num;
|
|
|
+ int.TryParse((sender as TextBox).Text, out num);
|
|
|
+ if (num > StrokeWidthSlider.Maximum)
|
|
|
+ {
|
|
|
+ (sender as TextBox).Text = StrokeWidthSlider.Maximum.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (num < StrokeWidthSlider.Minimum)
|
|
|
+ {
|
|
|
+ (sender as TextBox).Text = StrokeWidthSlider.Minimum.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|