Quellcode durchsuchen

bug-注释缩略图

OYXH\oyxh vor 2 Jahren
Ursprung
Commit
55729d012e

+ 2 - 1
PDF Office/Model/BOTA/AnnotationHandlerEventArgs.cs

@@ -2,6 +2,7 @@
 using ComPDFKitViewer.AnnotEvent;
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -24,7 +25,7 @@ namespace PDF_Office.Model.BOTA
         public int PageIndex { get; set; }
         public int AnnotIndex { get; set; }
         public AnnotHandlerEventArgs AnnotHandlerEventArgs { get; set; }
-        public WriteableBitmap WriteableBitmap { get; set; }
+        public BitmapImage WriteableBitmap { get; set; }
         public CPDFDocument Document { get; set; }
 
         public Rect ClientRect { get; set; }

+ 41 - 4
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -28,6 +28,7 @@ using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Configuration;
 using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -302,7 +303,7 @@ namespace PDF_Office.ViewModels.BOTA
                             AnnotationListItems[k].UpdateTime = items[j].UpdateTime;
                             if (items[j].EventType == AnnotArgsType.AnnotFreehand)
                             {
-                                WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, items[j].PageIndex, items[j].AnnotIndex);
+                                BitmapImage bitmap = GetAnnotImage(PdfViewer.Document, items[j].PageIndex, items[j].AnnotIndex);
                                 AnnotationListItems[k].WriteableBitmap = bitmap;
                             }
                             AnnotationListItems[k].Content = items[j].Content;
@@ -1131,7 +1132,7 @@ namespace PDF_Office.ViewModels.BOTA
             AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
             if (item.EventType == AnnotArgsType.AnnotFreehand)
             {
-                WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
+                BitmapImage bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
                 args.WriteableBitmap = bitmap;
             }
             args.ClientRect = item.ClientRect;
@@ -1158,7 +1159,7 @@ namespace PDF_Office.ViewModels.BOTA
         /// <param name="pageIndex"></param>
         /// <param name="annotIndex"></param>
         /// <returns></returns>
-        public WriteableBitmap GetAnnotImage(CPDFDocument doc, int pageIndex, int annotIndex)
+        public BitmapImage GetAnnotImage(CPDFDocument doc, int pageIndex, int annotIndex)
         {
             if (doc == null)
             {
@@ -1191,15 +1192,51 @@ namespace PDF_Office.ViewModels.BOTA
 
                     WriteableBitmap wirteBitmap = new WriteableBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Bgra32, null);
                     wirteBitmap.WritePixels(new Int32Rect(0, 0, drawWidth, drawHeight), bitmapArray, wirteBitmap.BackBufferStride, 0);
+                    BitmapImage bitmapImage = ConvertWriteableBitmapToBitmapImage(wirteBitmap, docPage.Rotation);
 
                     cPDFInk.SetRect(rawRect);
-                    return wirteBitmap;
+                    return bitmapImage;
                 }
             }
 
             return null;
         }
 
+        public BitmapImage ConvertWriteableBitmapToBitmapImage(WriteableBitmap wbm, int rotation)
+        {
+            BitmapImage bmImage = new BitmapImage();
+            using (MemoryStream stream = new MemoryStream())
+            {
+                PngBitmapEncoder encoder = new PngBitmapEncoder();
+                encoder.Frames.Add(BitmapFrame.Create(wbm));
+                encoder.Save(stream);
+                bmImage.BeginInit();
+                bmImage.CacheOption = BitmapCacheOption.OnLoad;
+                bmImage.StreamSource = stream;
+                switch (rotation)
+                {
+                    case 0:
+                        bmImage.Rotation = Rotation.Rotate0;
+                        break;
+
+                    case 1:
+                        bmImage.Rotation = Rotation.Rotate90;
+                        break;
+
+                    case 2:
+                        bmImage.Rotation = Rotation.Rotate180;
+                        break;
+
+                    case 3:
+                        bmImage.Rotation = Rotation.Rotate270;
+                        break;
+                }
+                bmImage.EndInit();
+                bmImage.Freeze();
+            }
+            return bmImage;
+        }
+
         /// <summary>
         /// listbox的itemsource发生变化时
         /// </summary>

+ 1 - 1
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SnapshotEditMenuViewModel.cs

@@ -105,7 +105,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 PDFViewer?.CropPage(0, rect, cropPageList);
                 PDFViewer.GoToPage(CurrentIndex);
 
-                //PDFViewer.UndoManager.CanSave = true;
+                PDFViewer.UndoManager.CanSave = true;
                 PDFViewer.SetMouseMode(MouseModes.PanTool);
                 if (SnapToolEvent != null)
                 {

+ 9 - 1
PDF Office/Views/BOTA/AnnotationListItem.xaml

@@ -352,7 +352,15 @@
             <Image
                 Name="ImageContext"
                 Grid.Row="1"
-                Source="{Binding WriteableBitmap}" />
+                Source="{Binding WriteableBitmap}">
+                <Image.RenderTransform>
+                    <TransformGroup>
+                        <TranslateTransform />
+                        <ScaleTransform />
+                        <RotateTransform />
+                    </TransformGroup>
+                </Image.RenderTransform>
+            </Image>
 
             <StackPanel Grid.Row="2" Margin="0,2">
                 <!--  附注  -->

+ 69 - 0
PDF Office/Views/BOTA/AnnotationListItem.xaml.cs

@@ -236,6 +236,75 @@ namespace PDF_Office.Views.BOTA
             double width = args.WriteableBitmap.Width;
             double height = args.WriteableBitmap.Height;
 
+            #region 方案一
+
+            CPDFDocument doc = args.Document;
+            CPDFPage docPage = doc.PageAtIndex(args.PageIndex, false);
+            if (docPage != null)
+            {
+                //BitmapImage bitmapImage = new BitmapImage();
+                //bitmapImage.BeginInit();
+                //bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
+                //bitmapImage.StreamSource = args.WriteableBitmap.StreamSource;
+
+                //switch (docPage.Rotation)
+                //{
+                //    case 0:
+                //        bitmapImage.Rotation = Rotation.Rotate0;
+                //        break;
+
+                //    case 1:
+                //        bitmapImage.Rotation = Rotation.Rotate90;
+                //        break;
+
+                //    case 2:
+                //        bitmapImage.Rotation = Rotation.Rotate180;
+                //        break;
+
+                //    case 3:
+                //        bitmapImage.Rotation = Rotation.Rotate270;
+                //        break;
+                //}
+                //bitmapImage.EndInit();
+                //ImageContext.Source = bitmapImage;
+
+                //switch (rotate)
+                //{
+                //    case 0:
+                //        RotateTransform rotateTransform = new RotateTransform(0);
+                //        ImageContext.RenderTransform = rotateTransform;
+                //        break;
+
+                //    case 1:
+                //        //rotateTransform = new RotateTransform(90);//90度
+                //        //ImageContext.RenderTransform = rotateTransform;
+                //        TransformGroup tg = ImageContext.RenderTransform as TransformGroup;
+                //        var tgnew = tg.CloneCurrentValue();
+                //        if (tgnew != null)
+                //        {
+                //            RotateTransform rt = tgnew.Children[2] as RotateTransform;
+                //            ImageContext.RenderTransformOrigin = new Point(0.5, 0.5);
+                //            rt.Angle = 90;
+                //        }
+
+                //        // 重新给图像赋值Transform变换属性
+                //        ImageContext.RenderTransform = tgnew;
+                //        break;
+
+                //    case 2:
+                //        rotateTransform = new RotateTransform(180);
+                //        ImageContext.RenderTransform = rotateTransform;
+                //        break;
+
+                //    case 3:
+                //        rotateTransform = new RotateTransform(270);
+                //        ImageContext.RenderTransform = rotateTransform;
+                //        break;
+                //}
+            }
+
+            #endregion 方案一
+
             if (width > 180)
             {
                 ImageContext.Stretch = Stretch.Uniform;