Пример #1
0
        /// <summary>
        /// 创建指定页的BMP图片对象
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="DrawMargin">是否绘制页边距线</param>
        /// <returns>创建的BMP图片对象</returns>
        public Metafile GetPageBmp2(PrintPage page, bool DrawMargin)
        {
            double rate = GraphicsUnitConvert.GetRate(
                myDocument.DocumentGraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            int width  = ( int )Math.Ceiling(myPages.PaperWidth / rate);
            int height = ( int )Math.Ceiling(myPages.PaperHeight / rate);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);

            Graphics  g1          = Graphics.FromImage(bmp);
            Rectangle rect        = new Rectangle(0, 0, bmp.Width, bmp.Height);
            string    folder      = CreateFolder();
            string    m_FilePath1 = folder + Guid.NewGuid().ToString() + ".wmf";
            Metafile  mf1         = new Metafile(m_FilePath1, g1.GetHdc(), rect, MetafileFrameUnit.Pixel);


            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(mf1))
            {
                //Add by wwj 2013-01-24
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                if (intBackColor.A != 0)
                {
                    g.Clear(this.intBackColor);
                }

                g.PageUnit = myDocument.DocumentGraphicsUnit;
                //Metafile mf = new Metafile(bmp,g.GetHdc(),);

                PageFrameDrawer drawer = new PageFrameDrawer();
                //Graphics gg = Graphics.FromImage(mf);

                drawer.DrawMargin   = DrawMargin;
                drawer.BackColor    = System.Drawing.Color.Transparent;
                drawer.BorderColor  = this.intBorderColor;
                drawer.BorderWidth  = 1;
                drawer.LeftMargin   = myPages.LeftMargin;
                drawer.TopMargin    = myPages.TopMargin;
                drawer.RightMargin  = myPages.RightMargin;
                drawer.BottomMargin = myPages.BottomMargin;

                drawer.Bounds = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPages.PaperWidth,
                    myPages.PaperHeight);

                drawer.DrawPageFrame(g, System.Drawing.Rectangle.Empty);

                DrawPage(page, g, page.Bounds, true);
            }
            return(mf1);
        }
Пример #2
0
        /// <summary>
        /// 创建指定页的图元数据
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="DrawMargin">是否绘制边距线</param>
        /// <returns>包含图元数据的字节数组</returns>
        public byte[] GetMetafile(PrintPage page, bool DrawMargin)
        {
            XPageSettings pageSettings = page.PageSettings;

            System.Drawing.Imaging.Metafile meta = null;
            using (DeviceContexts dc = DeviceContexts.CreateCompatibleDC(IntPtr.Zero))
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                meta = new System.Drawing.Imaging.Metafile(
                    stream,
                    dc.HDC,
                    new System.Drawing.Rectangle(
                        0,
                        0,
                        (int)page.PageSettings.ViewPaperWidth,
                        (int)page.PageSettings.ViewPaperHeight),
                    //System.Drawing.Imaging.MetafileFrameUnit.Document );
                    PrintUtil.ConvertUnit(myDocument.DocumentGraphicsUnit));
                using (System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(meta))
                {
                    if (intBackColor.A != 0)
                    {
                        g2.Clear(this.intBackColor);
                    }

                    g2.PageUnit = myDocument.DocumentGraphicsUnit;

                    PageFrameDrawer drawer = new PageFrameDrawer();
                    drawer.DrawMargin   = DrawMargin;
                    drawer.BackColor    = System.Drawing.Color.Transparent;
                    drawer.BorderColor  = this.intBorderColor;
                    drawer.BorderWidth  = 1;
                    drawer.LeftMargin   = (int)page.ViewLeftMargin;
                    drawer.TopMargin    = (int)page.ViewTopMargin;
                    drawer.RightMargin  = (int)page.ViewRightMargin;
                    drawer.BottomMargin = (int)page.ViewBottomMargin;

                    drawer.Bounds = new System.Drawing.Rectangle(
                        0,
                        0,
                        (int)pageSettings.ViewPaperWidth,
                        (int)pageSettings.ViewPaperHeight);
                    drawer.BackgroundImage = this.PageBackgroundImage;
                    g2.ScaleTransform(this.XZoomRate, this.YZoomRate);
                    drawer.DrawPageFrame(g2, System.Drawing.Rectangle.Empty);

                    DrawPage(page, g2, page.Bounds, true);
                }
                meta.Dispose();
                dc.Dispose();
                return(stream.ToArray());
            }
        }
Пример #3
0
        /// <summary>
        /// 创建指定页的BMP图片对象
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="DrawMargin">是否绘制页边距线</param>
        /// <returns>创建的BMP图片对象</returns>
        public System.Drawing.Bitmap GetPageBmp(PrintPage page, bool DrawMargin)
        {
            XPageSettings pageSettings = page.PageSettings;
            double        rate         = GraphicsUnitConvert.GetRate(
                myDocument.DocumentGraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            int width  = (int)Math.Ceiling(pageSettings.ViewPaperWidth / rate);
            int height = (int)Math.Ceiling(pageSettings.ViewPaperHeight / rate);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                if (intBackColor.A != 0)
                {
                    g.Clear(this.intBackColor);
                }

                g.PageUnit = myDocument.DocumentGraphicsUnit;

                PageFrameDrawer drawer = new PageFrameDrawer();
                drawer.DrawMargin   = DrawMargin;
                drawer.BackColor    = System.Drawing.Color.Transparent;
                drawer.BorderColor  = this.intBorderColor;
                drawer.BorderWidth  = 1;
                drawer.LeftMargin   = (int)page.ViewLeftMargin;
                drawer.TopMargin    = (int)page.ViewTopMargin;
                drawer.RightMargin  = (int)page.ViewRightMargin;
                drawer.BottomMargin = (int)page.ViewBottomMargin;

                drawer.Bounds = new System.Drawing.Rectangle(
                    0,
                    0,
                    (int)page.ViewPaperWidth,
                    (int)page.ViewPaperHeight);
                drawer.BackgroundImage = this.PageBackgroundImage;
                drawer.DrawPageFrame(g, System.Drawing.Rectangle.Empty);

                DrawPage(page, g, page.Bounds, true);
            }
            return(bmp);
        }
Пример #4
0
        /// <summary>
        /// 绘制页面框架
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">图形绘制对象</param>
        /// <param name="Focused">该页是否是当前页</param>
        /// <param name="FillBackGround">是否填充背景</param>
        protected void DrawPageFrame(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle ClipRectangle,
            bool FillBackGround)
        {
            if (myPage == null || _Pages.Contains(myPage) == false)
            {
                return;
            }
            System.Drawing.Rectangle bounds = myPage.ClientBounds;
            bounds.Offset(this.AutoScrollPosition);
            // 绘制页面阴影
            //int ShadowSize = 5;
            //g.FillRectangle(System.Drawing.Brushes.Black, bounds.Right - 1 , bounds.Top + ShadowSize, ShadowSize, bounds.Height-1);
            //g.FillRectangle(System.Drawing.Brushes.Black , bounds.Left + ShadowSize, bounds.Bottom - 1 , bounds.Width-1, ShadowSize);

            //System.Drawing.Rectangle ShadowRect = bounds;
            //ShadowRect.Offset(10 , 10 );
            //using (System.Drawing.Pen p = new System.Drawing.Pen( System.Drawing.Color.Gray , 10 ))
            //{
            //    g.DrawRectangle(p, ShadowRect);
            //}
            PageFrameDrawer drawer = new PageFrameDrawer();

            drawer.BorderWidth = 1;
            drawer.Bounds      = bounds;
            drawer.Margins     = myPage.ClientMargins;
            if (myPage == this.CurrentPage)
            {
                if (this.Enabled)                                                            // info.Enabled )
                {
                    drawer.BorderColor = System.Drawing.ColorTranslator.FromHtml("#EEAA57"); // System.Drawing.Color.Red;
                    drawer.BorderWidth = 3;
                }
                else
                {
                    drawer.BorderColor = System.Drawing.Color.LightGray;
                    drawer.BorderWidth = 3;
                }
            }
            else
            {
                drawer.BorderWidth = 3;
                drawer.BorderColor = System.Drawing.Color.Black;
            }
            drawer.BackColor = FillBackGround ? this.PageBackColor : System.Drawing.Color.Transparent;

            //this.FixedBackground = false;


            drawer.DrawPageFrame(g, ClipRectangle);



            //XDesignerDrawer.PageFrameDrawer.DrawPageFrame(
            //    bounds ,
            //    this.myClientMargins ,
            //    g ,
            //    System.Drawing.Rectangle.Empty ,
            //    Focused ,
            //    FillBackGround ? this.PageBackColor : System.Drawing.Color.Transparent );
        }