|
@@ -98,14 +98,14 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
if (e.IsCreate)
|
|
|
{
|
|
|
pdfViewerControl.UpdateAnnotFrame();
|
|
|
+ if (currentAnnotationType == CPDFAnnotationType.Image || currentAnnotationType == CPDFAnnotationType.Stamp || currentAnnotationType == CPDFAnnotationType.Signature)
|
|
|
+ {
|
|
|
+ pdfViewerControl.SetToolType(ToolType.Pan);
|
|
|
+ pdfViewerControl.SetIsVisibleCustomMouse(false);
|
|
|
+ pdfViewerControl.SetIsShowStampMouse(false);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- if (currentAnnotationType == CPDFAnnotationType.Image || currentAnnotationType == CPDFAnnotationType.Stamp || currentAnnotationType == CPDFAnnotationType.Signature)
|
|
|
- {
|
|
|
- pdfViewerControl.SetToolType(ToolType.Pan);
|
|
|
- pdfViewerControl.SetIsVisibleCustomMouse(false);
|
|
|
- pdfViewerControl.SetIsShowStampMouse(false);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -933,46 +933,48 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- BitmapImage image = new BitmapImage(new Uri(openFileDialog.FileName));
|
|
|
-
|
|
|
- PngBitmapEncoder encoder = new PngBitmapEncoder();
|
|
|
- encoder.Frames.Add(BitmapFrame.Create(image));
|
|
|
- MemoryStream memoryStream = new MemoryStream();
|
|
|
- encoder.Save(memoryStream);
|
|
|
- stampParam.ImageStream = memoryStream;
|
|
|
- stampParam.Transparency = 255;
|
|
|
- stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
|
|
|
- stampParam.StampType = C_STAMP_TYPE.IMAGE_STAMP;
|
|
|
-
|
|
|
- BitmapFrame frame = null;
|
|
|
- if (encoder != null && encoder.Frames.Count > 0)
|
|
|
- {
|
|
|
- frame = encoder.Frames[0];
|
|
|
- }
|
|
|
- if (frame != null)
|
|
|
+ using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
|
{
|
|
|
- byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
- if (frame.Format != PixelFormats.Bgra32)
|
|
|
+
|
|
|
+ PngBitmapEncoder encoder = new PngBitmapEncoder();
|
|
|
+ encoder.Frames.Add(BitmapFrame.Create(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None));
|
|
|
+ MemoryStream memoryStream = new MemoryStream();
|
|
|
+ encoder.Save(memoryStream);
|
|
|
+ stampParam.ImageStream = memoryStream;
|
|
|
+ stampParam.Transparency = 255;
|
|
|
+ stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
|
|
|
+ stampParam.StampType = C_STAMP_TYPE.IMAGE_STAMP;
|
|
|
+
|
|
|
+ BitmapFrame frame = null;
|
|
|
+ if (encoder != null && encoder.Frames.Count > 0)
|
|
|
{
|
|
|
- FormatConvertedBitmap covert = new FormatConvertedBitmap(
|
|
|
- frame,
|
|
|
- PixelFormats.Bgra32,
|
|
|
- frame.Palette,
|
|
|
- 0);
|
|
|
- covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
|
|
|
+ frame = encoder.Frames[0];
|
|
|
}
|
|
|
- else
|
|
|
+ if (frame != null)
|
|
|
{
|
|
|
- frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
|
|
|
+ byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
|
|
|
+ if (frame.Format != PixelFormats.Bgra32)
|
|
|
+ {
|
|
|
+ FormatConvertedBitmap covert = new FormatConvertedBitmap(
|
|
|
+ frame,
|
|
|
+ PixelFormats.Bgra32,
|
|
|
+ frame.Palette,
|
|
|
+ 0);
|
|
|
+ covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
|
|
|
+ }
|
|
|
+ pdfViewerControl.SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
|
|
|
}
|
|
|
- pdfViewerControl.SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
|
|
|
- }
|
|
|
|
|
|
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
|
|
|
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
|
|
|
- pdfViewerControl.SetIsVisibleCustomMouse(true);
|
|
|
- pdfViewerControl.SetIsShowStampMouse(true);
|
|
|
- pdfViewerControl.SetAnnotParam(stampParam);
|
|
|
+ pdfViewerControl.SetToolType(ToolType.CreateAnnot);
|
|
|
+ pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
|
|
|
+ pdfViewerControl.SetIsVisibleCustomMouse(true);
|
|
|
+ pdfViewerControl.SetIsShowStampMouse(true);
|
|
|
+ pdfViewerControl.SetAnnotParam(stampParam);
|
|
|
+ }
|
|
|
}
|
|
|
catch
|
|
|
{
|