Browse Source

其他-Demo的图章图片设置

zhuyi 1 year ago
parent
commit
d3892b230a

+ 32 - 1
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -21,6 +21,7 @@ using ComPDFKit.Import;
 using ComPDFKitViewer.BaseObject;
 using ComPDFKitViewer.Widget;
 using ComPDFKit.PDFDocument;
+using System.Text;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -410,11 +411,41 @@ namespace Compdfkit_Tools.PDFControl
                 case CPDFAnnotationType.Stamp:
                     {
                         StampParam stampParam = new StampParam();
-                        annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
+                        stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
                         CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
                         SetStamp(ref stampParam, stampData);
                         annotHandlerEventArgs = stampParam;
                         pdfViewerControl.PDFToolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
+
+                        stampParam.ImageStream.Seek(0, SeekOrigin.Begin);
+                        BitmapDecoder decoder = BitmapDecoder.Create(stampParam.ImageStream,
+                                BitmapCreateOptions.None,
+                                BitmapCacheOption.Default);
+                        BitmapFrame frame = null;
+                        if (decoder != null && decoder.Frames.Count > 0)
+                        {
+                            frame = decoder.Frames[0];
+                        }
+                        if (frame != null)
+                        {
+                            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.PDFViewTool.GetCPDFViewer().SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
+                        }
+                        pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(true);
+                        pdfViewerControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(true);
                     }
                     break;
                 case CPDFAnnotationType.Signature: