• Aword无题


     /// 
            /// 书签处插入处理后的图片
            /// 
            /// 
            /// 
            /// 
            /// 剩下大小
            /// 
            public static bool InsertCutImage(Document Doc, Image Img, string markName,int ShengxiaNn)
            {
                if (Doc.Range.Bookmarks[markName] != null && Img != null)
                {
                    try
                    {
                        Image ImageZhuanhuan;
                        ImageZhuanhuan = new Bitmap(Img);
                        Img.Dispose();
                        DocumentBuilder builder = new DocumentBuilder(Doc);
                        builder.MoveToBookmark(markName);
    
                        double displayWidth = 600;//显示宽度
                        double displayHeight = 610;//显示高度度
                        double zoomRate = 0;
                        if ((double)ImageZhuanhuan.Width / (double)ImageZhuanhuan.Height < displayWidth / displayHeight)
                        {
                            zoomRate = displayHeight / ImageZhuanhuan.Height;//缩放比例
                            displayWidth = ImageZhuanhuan.Width * zoomRate;//显示高度 
                        }
                        else
                        {
                            zoomRate = displayWidth / ImageZhuanhuan.Width;//缩放比例
                            displayHeight = ImageZhuanhuan.Height * zoomRate;//显示高度 
                        }
                        int FirstImageHight = (int)Math.Floor( (double)ShengxiaNn/zoomRate);//第一张图片的大小
                        Image ImageFirst = null;
                        Image ImageSecond= null;
                        if (FirstImageHight >= ShengxiaNn)//如果大于则需要分解
                        {
                            ImageFirst = ImageZhuanhuan; 
                        }
                        else
                        {
                            int FirstHeight = FirstImageHight;//第一个图片的高度
                            int SecondHeight = ImageZhuanhuan.Height - FirstHeight;//第二个图片的高度
                            ImageFirst = Common.ImageHelper.CaptureImage(ImageZhuanhuan,0,0,ImageZhuanhuan.Width,FirstHeight);
                            ImageSecond = Common.ImageHelper.CaptureImage(ImageZhuanhuan, 0, FirstImageHight, ImageZhuanhuan.Width, SecondHeight); 
                        }
                        if (ImageFirst!=null)
                        {
                            Shape shape = builder.InsertImage(ImageFirst);
                            shape.Width = displayWidth;//ImageZhuanhuan.Width; 
                            shape.Height = displayHeight;//ImageZhuanhuan.Height;  基本是以上下高度为准
                            shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
                            //shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
                            shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
                            shape.WrapType = WrapType.Square;
                            if (ImageSecond != null)
                            {
                                //Run run = Doc.GetChildNodes(NodeType.Run, true)[Doc.GetChildNodes(NodeType.Run, true).Count - 1] as Run;
                                Run run = Doc.GetChildNodes(NodeType.Run, true)[Doc.GetChildNodes(NodeType.Run, true).Count + 1] as Run;
                                builder.MoveTo(run);
                                Shape shapeSec = builder.InsertImage(ImageSecond);
                                shapeSec.Width = displayWidth;//ImageZhuanhuan.Width; 
                                shapeSec.Height = displayHeight;//ImageZhuanhuan.Height;  基本是以上下高度为准
                                shapeSec.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
                                //shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
                                shapeSec.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
                                shapeSec.WrapType = WrapType.Square;
                            }
                        }
                        //if (ImageSecond != null)
                        //{
                        //    Shape shape = builder.InsertImage(ImageSecond);
                        //    shape.Width = displayWidth;//ImageZhuanhuan.Width; 
                        //    shape.Height = displayHeight;//ImageZhuanhuan.Height;  基本是以上下高度为准
                        //    shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
                        //    //shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;//图片居中对齐
                        //    shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
                        //    shape.WrapType = WrapType.Square;
                        //}  
                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }
    
                }
                else
                {
                    return false;
                }
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
  • 相关阅读:
    MySQL体系结构和四层架构介绍
    CrossFTP
    用户身份管理(CIAM)如何帮助业务持续增长?|身份云研究院
    C语言之文件操作
    Python性能优化
    Java 设计模式实战系列—工厂模式
    Golang swagger :missing required param comment parameters
    Python 爬虫入门(十一):Scrapy高级应用之并发与分布式「详细介绍」
    大数据毕设选题 - 深度学习火焰识别检测系统(python YOLO)
    乱打日志的男孩运气怎么样我不知道,加班肯定很多
  • 原文地址:https://blog.csdn.net/weixin_40029679/article/details/126751843