浏览代码

ComPDFKit.Tool(Win) - 修复设置带黑色图章透明度旋转后还原问题

liyuxuan 2 月之前
父节点
当前提交
5a23e37bf5

+ 20 - 1
Demo/Examples/ComPDFKit.Tool/Help/PDFHelp.cs

@@ -173,7 +173,26 @@ namespace ComPDFKit.Tool.Help
                     frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
                 }
 
-                imageWidth = frame.PixelWidth;
+                int stride = ((int)frame.PixelWidth) * 4;
+                for (int i = 0; i < (int)(frame.PixelHeight); i++)
+                {
+                    for (int j = 0; j < (int)(frame.PixelWidth); j++)
+                    {
+                        byte b = imageData[i * stride + j * 4];
+                        byte g = imageData[i * stride + j * 4 + 1];
+                        byte r = imageData[i * stride + j * 4 + 2];
+                        byte a = imageData[i * stride + j * 4 + 3];
+
+                        if (a == 0 && b == 0 && g == 0 && r == 0)
+                        {
+                            imageData[i * stride + j * 4] = 255;
+                            imageData[i * stride + j * 4 + 1] = 255;
+                            imageData[i * stride + j * 4 + 2] = 255;
+                            continue;
+                        }
+                    }
+                }
+                        imageWidth = frame.PixelWidth;
                 imageHeight = frame.PixelHeight;
             }
         }

+ 5 - 14
Demo/Examples/ComPDFKit.Tool/UndoManger/AnnotHistory/StampAnnotHistory.cs

@@ -284,11 +284,6 @@ namespace ComPDFKit.Tool.UndoManger
                             continue;
                         }
 
-                        if (a == 0 && b == 0 && g == 0 && r == 0)
-                        {
-                            continue;
-                        }
-
                         if (a == 0 && opacity > 0)
                         {
                             imageData[i * stride + j * 4] = 255;
@@ -360,8 +355,12 @@ namespace ComPDFKit.Tool.UndoManger
 
                             if (a == 0 && b == 0 && g == 0 && r == 0)
                             {
+                                imageData[i * stride + j * 4] = 255;
+                                imageData[i * stride + j * 4 + 1] = 255;
+                                imageData[i * stride + j * 4 + 2] = 255;
                                 continue;
                             }
+
                             imageData[i * stride + j * 4 + 3] = (byte)(opacity * 255);
                         }
                     }
@@ -417,15 +416,7 @@ namespace ComPDFKit.Tool.UndoManger
                         {
                             continue;
                         }
-
-                        if (a == 0 && b == 0 && g == 0 && r == 0)
-                        {
-                            continue;
-                        }
-                        if (a == 0 && b == 0 && g == 0 && r == 0)
-                        {
-                            continue;
-                        }
+                    
                         if (a == 0 && annotOpacity > 0)
                         {
                             imageData[i * stride + j * 4] = 255;