Browse Source

PDFAnnotation(windows)-添加异常图片崩溃,和滑动条拖拽崩溃问题,以及滑动条小数点问题修复

zhuyi 1 year ago
parent
commit
d8de9face9

+ 2 - 2
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml

@@ -346,8 +346,8 @@
                     </Grid>
                     <StackPanel Grid.Row="3" Grid.Column="2" VerticalAlignment="Center" Orientation="Horizontal">
                         <TextBlock Text="Line Width"  VerticalAlignment="Center" />
-                        <Slider  x:Name="StrokeWidthSlider" Width="96" Margin="12,0,0,0" Value="4" VerticalAlignment="Center" ValueChanged="StrokeWidth_ValueChanged"/>
-                        <TextBox Text="{Binding ElementName=StrokeWidthSlider, Path=Value,Mode=TwoWay}" Width="72" Height="32" VerticalContentAlignment="Center"/>
+                        <Slider  x:Name="StrokeWidthSlider" Width="96" Margin="12,0,0,0" Value="4" Minimum="1" IsSnapToTickEnabled="True"  Maximum="10" VerticalAlignment="Center" ValueChanged="StrokeWidth_ValueChanged"/>
+                        <TextBox Text="{Binding ElementName=StrokeWidthSlider, Path=Value,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="72" Height="32" VerticalContentAlignment="Center" TextChanged="TextBox_TextChanged"/>
                     </StackPanel>
                     <StackPanel
                             Grid.Row="3"

+ 46 - 19
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml.cs

@@ -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();
+                }
+            }
+        }
     }
 }