Переглянути джерело

综合-添加图片的不出现图片问题,添加图片路径打开bug修复

zhuyi 11 місяців тому
батько
коміт
7f5e0128f8

+ 42 - 40
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -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
                         {

+ 0 - 6
Demo/Examples/Compdfkit_Tools/Edit/ContentEditCOntrol/ContentEditControl.xaml.cs

@@ -257,12 +257,6 @@ namespace Compdfkit_Tools.PDFControl
                     ClearPDFEditState(senderBtn);
                     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);
-
                         bool SetImage = PdfViewControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(openFileDialog.FileName);
                         PdfViewControl.PDFToolManager.SetCreateImagePath(openFileDialog.FileName);
                         PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(SetImage);