|
@@ -108,58 +108,65 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
|
|
|
string name = Guid.NewGuid().ToString();
|
|
|
if (!string.IsNullOrEmpty(CustomStampPath))
|
|
|
{
|
|
|
- BitmapImage image = new BitmapImage(new Uri(FilePath));
|
|
|
- double scale = Math.Min((double)600 / image.PixelWidth, (double)600 / image.PixelHeight);
|
|
|
- scale = Math.Min(scale, 1);
|
|
|
- string ext = Path.GetExtension(FilePath);
|
|
|
- if (ext.ToUpper() == ".PNG")
|
|
|
+ try
|
|
|
{
|
|
|
- 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))
|
|
|
+ BitmapImage image = new BitmapImage(new Uri(FilePath));
|
|
|
+ double scale = Math.Min((double)600 / image.PixelWidth, (double)600 / image.PixelHeight);
|
|
|
+ scale = Math.Min(scale, 1);
|
|
|
+ string ext = Path.GetExtension(FilePath);
|
|
|
+ if (ext.ToUpper() == ".PNG")
|
|
|
{
|
|
|
- encoder.Save(stream);
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty(SaveToPath))
|
|
|
- {
|
|
|
- DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
|
|
|
- if (CreatedFilePathFolder.Exists)
|
|
|
+ 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;
|
|
|
+ ImageImage.Source = targetBitmap;
|
|
|
+ StampWidth = targetBitmap.PixelWidth;
|
|
|
+ StampHeight = targetBitmap.PixelHeight;
|
|
|
+ AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
- SaveToPath = path;
|
|
|
- ImageImage.Source = targetBitmap;
|
|
|
- StampWidth = targetBitmap.PixelWidth;
|
|
|
- StampHeight = targetBitmap.PixelHeight;
|
|
|
- AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- BitmapEncoder encoder = new JpegBitmapEncoder();
|
|
|
- TransformedBitmap 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))
|
|
|
- {
|
|
|
- encoder.Save(stream);
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty(SaveToPath))
|
|
|
+ else
|
|
|
{
|
|
|
- DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
|
|
|
- if (CreatedFilePathFolder.Exists)
|
|
|
+ BitmapEncoder encoder = new JpegBitmapEncoder();
|
|
|
+ TransformedBitmap 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))
|
|
|
+ {
|
|
|
+ encoder.Save(stream);
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty(SaveToPath))
|
|
|
{
|
|
|
- Directory.Delete(SaveToPath, true);
|
|
|
+ DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(SaveToPath);
|
|
|
+ if (CreatedFilePathFolder.Exists)
|
|
|
+ {
|
|
|
+ Directory.Delete(SaveToPath, true);
|
|
|
+ }
|
|
|
}
|
|
|
+ SaveToPath = path;
|
|
|
+ ImageImage.Source = targetBitmap;
|
|
|
+ StampWidth = targetBitmap.PixelWidth;
|
|
|
+ StampHeight = targetBitmap.PixelHeight;
|
|
|
+ AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
+ SaveBtn.IsEnabled = true;
|
|
|
}
|
|
|
- SaveToPath = path;
|
|
|
- ImageImage.Source = targetBitmap;
|
|
|
- StampWidth = targetBitmap.PixelWidth;
|
|
|
- StampHeight = targetBitmap.PixelHeight;
|
|
|
- AddImageBtn.Visibility = Visibility.Collapsed;
|
|
|
- SaveBtn.IsEnabled = true;
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -360,7 +367,6 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
|
|
|
return;
|
|
|
}
|
|
|
SaveToImage(openFile.FileName);
|
|
|
- SaveBtn.IsEnabled = true;
|
|
|
}
|
|
|
|
|
|
|