Browse Source

ComPDFKit.Controls(win) - 处理复制和提取页面图片崩溃的问题

TangJinZhou 5 months ago
parent
commit
29c59ea55c

+ 28 - 2
Demo/Examples/Compdfkit.Controls/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -18,6 +18,8 @@ using ComPDFKit.Tool;
 using ComPDFKit.PDFPage;
 using ComPDFKitViewer.Widget;
 using ComPDFKit.Tool.Help;
+using ComPDFKit.Tool.DrawTool;
+using System.Collections.Generic;
 
 namespace ComPDFKit.Controls.PDFControl
 {
@@ -319,11 +321,23 @@ baseWidget.GetAnnotData().Annot);
             System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
             if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
-                var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
+                PageImageItem image = null;
+                Dictionary<int, List<PageImageItem>> pageImageDict = PDFViewControl.FocusPDFViewTool.GetSelectImageItems();
+                if (pageImageDict != null && pageImageDict.Count > 0)
+                {
+                    foreach (int pageIndex in pageImageDict.Keys)
+                    {
+                        List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                        image = imageItemList[0];
+                        break;
+                    }
+                }
+
                 if (image == null)
                 {
                     return;
                 }
+
                 CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
                 string savePath = Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
                 string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
@@ -337,11 +351,23 @@ baseWidget.GetAnnotData().Annot);
 
         private void CopyImage_Click(object sender, RoutedEventArgs e)
         {
-            var image = PDFViewControl.FocusPDFViewTool.GetSelectImage();
+            PageImageItem image = null;
+            Dictionary<int, List<PageImageItem>> pageImageDict = PDFViewControl.FocusPDFViewTool.GetSelectImageItems();
+            if (pageImageDict != null && pageImageDict.Count > 0)
+            {
+                foreach (int pageIndex in pageImageDict.Keys)
+                {
+                    List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                    image = imageItemList[0];
+                    break;
+                }
+            }
+
             if (image == null)
             {
                 return;
             }
+
             CPDFPage page = PDFViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
             string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
             page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);

+ 26 - 12
Demo/Examples/Compdfkit.Controls/Measure/MeasureControl.xaml.cs

@@ -9,26 +9,17 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics;
 using System.Drawing;
-using System.Globalization;
 using System.IO;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 using ComPDFKit.PDFPage;
 using ComPDFKit.Tool.Help;
-using ComPDFKit.Viewer.Annot;
 using ComPDFKitViewer.BaseObject;
 using Path = System.IO.Path;
-
+using ComPDFKit.Tool.DrawTool;
 
 namespace ComPDFKit.Controls.Measure
 {
@@ -192,11 +183,23 @@ namespace ComPDFKit.Controls.Measure
             System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
             if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
-                var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
+                PageImageItem image = null;
+                Dictionary<int, List<PageImageItem>> pageImageDict = PdfViewControl.FocusPDFViewTool.GetSelectImageItems();
+                if (pageImageDict != null && pageImageDict.Count > 0)
+                {
+                    foreach (int pageIndex in pageImageDict.Keys)
+                    {
+                        List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                        image = imageItemList[0];
+                        break;
+                    }
+                }
+
                 if (image == null)
                 {
                     return;
                 }
+
                 CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
                 string savePath = System.IO.Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
                 string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid() + ".jpg");
@@ -210,7 +213,18 @@ namespace ComPDFKit.Controls.Measure
 
         private void CopyImage_Click(object sender, RoutedEventArgs e)
         {
-            var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
+            PageImageItem image = null;
+            Dictionary<int, List<PageImageItem>> pageImageDict = PdfViewControl.FocusPDFViewTool.GetSelectImageItems();
+            if (pageImageDict != null && pageImageDict.Count > 0)
+            {
+                foreach (int pageIndex in pageImageDict.Keys)
+                {
+                    List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                    image = imageItemList[0];
+                    break;
+                }
+            }
+
             if (image == null)
             {
                 return;

+ 30 - 8
Demo/Examples/Compdfkit.Controls/PDFView/RegularViewerControl.xaml.cs

@@ -7,17 +7,15 @@ using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media.Imaging;
-using ComPDFKit.Controls.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
-using ComPDFKit.Controls.Common;
 using ComPDFKit.Controls.Helper;
 using ComPDFKit.Controls.PDFControl;
 using ComPDFKit.PDFPage;
-using ComPDFKit.PDFPage.Edit;
-using ComPDFKitViewer;
 using ComPDFKit.Tool;
 using ContextMenu = System.Windows.Controls.ContextMenu;
 using MenuItem = System.Windows.Controls.MenuItem;
 using UserControl = System.Windows.Controls.UserControl;
+using System.Collections.Generic;
+using ComPDFKit.Tool.DrawTool;
 
 namespace ComPDFKit.Controls.PDFView
 {
@@ -244,11 +242,23 @@ namespace ComPDFKit.Controls.PDFView
             System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
             if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
-                var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
-                if(image == null)
+                PageImageItem image = null;
+                Dictionary<int, List<PageImageItem>> pageImageDict = PdfViewControl.FocusPDFViewTool.GetSelectImageItems();
+                if (pageImageDict != null && pageImageDict.Count > 0)
+                {
+                    foreach (int pageIndex in pageImageDict.Keys)
+                    {
+                        List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                        image = imageItemList[0];
+                        break;
+                    }
+                }
+
+                if (image == null)
                 {
                     return;
                 }
+
                 CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
                 string savePath = Path.Combine(folderDialog.SelectedPath, Guid.NewGuid() + ".jpg");
                 string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
@@ -262,11 +272,23 @@ namespace ComPDFKit.Controls.PDFView
 
         private void CopyImage_Click(object sender, RoutedEventArgs e)
         {
-            var image = PdfViewControl.FocusPDFViewTool.GetSelectImage();
-            if(image == null)
+            PageImageItem image = null;
+            Dictionary<int, List<PageImageItem>> pageImageDict = PdfViewControl.FocusPDFViewTool.GetSelectImageItems();
+            if (pageImageDict != null && pageImageDict.Count > 0)
+            {
+                foreach (int pageIndex in pageImageDict.Keys)
+                {
+                    List<PageImageItem> imageItemList = pageImageDict[pageIndex];
+                    image = imageItemList[0];
+                    break;
+                }
+            }
+
+            if (image == null)
             {
                 return;
             }
+
             CPDFPage page = PdfViewControl.PDFToolManager.GetDocument().PageAtIndex(image.PageIndex);
             string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".jpg");
             page.GetImgSelection().GetImgBitmap(image.ImageIndex, tempPath);