SetClip() public method

public SetClip ( Graphics g ) : void
g Graphics
return void
Ejemplo n.º 1
2
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw the gridlines.
        /// </summary>
        /// <param name="graphics">Reference to the GDI+ drawing surface.</param>
        public void Draw(System.Drawing.Graphics graphics)
        {
            using (Pen graphAreaPen = new Pen(m_ParentGraph.GridlineColor))
            {
                graphAreaPen.DashStyle = DashStyle.Dash;
                using (Brush graphAreaBrush = new SolidBrush(m_ParentGraph.GraphAreaColor))
                {
                    graphics.FillRectangle(graphAreaBrush, m_ParentGraph.GraphArea);
                    graphics.DrawRectangle(graphAreaPen, m_ParentGraph.GraphArea);

                    if ((m_ParentGraph.Gridlines & GridStyles.Horizontal) == GridStyles.Horizontal)
                    {
                        graphics.SetClip(m_ParentGraph.GraphArea);

                        int gridSize = m_ParentGraph.GraphArea.Height / m_ParentGraph.GraduationsY;
                        for (int i = 0; i < m_ParentGraph.GraphArea.Height; i += gridSize)
                        {
                            graphics.DrawLine(graphAreaPen, m_ParentGraph.GraphArea.Left, m_ParentGraph.GraphArea.Top + i, m_ParentGraph.GraphArea.Right, m_ParentGraph.GraphArea.Top + i);
                        }
                    }

                    if ((m_ParentGraph.Gridlines & GridStyles.Vertical) == GridStyles.Vertical)
                    {
                        graphics.SetClip(m_ParentGraph.GraphArea);

                        int gridSize = m_ParentGraph.GraphArea.Width / m_ParentGraph.GraduationsX;
                        for (int i = 0; i < m_ParentGraph.GraphArea.Width; i += gridSize)
                        {
                            graphics.DrawLine(graphAreaPen, m_ParentGraph.GraphArea.Left + i, m_ParentGraph.GraphArea.Bottom, m_ParentGraph.GraphArea.Left + i, m_ParentGraph.GraphArea.Top);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void DrawGlass(Rectangle rectangle, Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            var clipPath = GetRoundedRectanglePath(rectangle);

            graphics.SetClip(clipPath);

            var glassRectangle = new Rectangle(rectangle.Location, new Size(rectangle.Width, rectangle.Height/2));

            // Apply a glass look
            Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
                                                       Color.FromArgb(32, 255, 255, 255), 90.0f);

            var glassPath = GetRoundedRectanglePath(glassRectangle);

            graphics.FillPath(glassBrush, glassPath);

            glassPath.Dispose();
            glassBrush.Dispose();

            glassRectangle = new Rectangle(0, rectangle.Height - (rectangle.Height/4), rectangle.Width,
                                           rectangle.Height*3);
            glassPath = GetRoundedRectanglePath(glassRectangle);
            glassBrush = new SolidBrush(Color.FromArgb(16, Color.White));

            glassBrush.Dispose();
            glassPath.Dispose();

            graphics.SetClip(rectangle);
            clipPath.Dispose();
        }
Ejemplo n.º 4
0
        protected override void PaintRestore(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled)
        {
            SmoothingMode sm = g.SmoothingMode;
            g.SmoothingMode = SmoothingMode.None;

            Size s = new Size(10, 10);
            Rectangle rm = GetSignRect(r, s);
            Region oldClip = g.Clip;

            LinearGradientColorTable buttonTable = isEnabled ? ct.Foreground : new LinearGradientColorTable(GetDisabledColor(ct.Foreground.Start), GetDisabledColor(ct.Foreground.End), ct.Foreground.GradientAngle);
            using (Brush fill = DisplayHelp.CreateBrush(rm, ct.Foreground))
            {
                Rectangle inner = new Rectangle(rm.X + 4, rm.Y + 2, 6, 4);
                g.SetClip(inner, CombineMode.Exclude);
                g.SetClip(new Rectangle(rm.X + 1, rm.Y + 5, 6, 4), CombineMode.Exclude);

                g.FillRectangle(fill, rm.X + 3, rm.Y, 8, 7);
                g.ResetClip();

                inner = new Rectangle(rm.X + 1, rm.Y + 5, 6, 4);
                g.SetClip(inner, CombineMode.Exclude);
                g.FillRectangle(fill, rm.X, rm.Y + 3, 8, 7);
                g.ResetClip();
            }
            if (oldClip != null)
            {
                g.Clip = oldClip;
                oldClip.Dispose();
            }
            g.SmoothingMode = sm;
        }
Ejemplo n.º 5
0
        public static void DrawImage(Graphics g, Image image, ImageLayoutMode layoutMode, Rectangle rect)
        {
            // Graphics g = Graphics.FromHwnd(IntPtr.Zero);

            if (layoutMode == ImageLayoutMode.None)
            {
                Rectangle tempRect = new Rectangle(rect.X, rect.Y, image.Width, image.Height);
                g.SetClip(rect);
                g.DrawImage(image, tempRect);
                g.ResetClip();
            }
            else if (layoutMode == ImageLayoutMode.Stretch)
            {
                g.DrawImage(image, rect);
            }
            else if (layoutMode == ImageLayoutMode.FitToWidth)
            {
                g.SetClip(rect);
                Size newSize = new Size(rect.Width, rect.Width * image.Height / image.Width);
                g.DrawImage(image, new Rectangle(rect.Location, newSize));
                g.ResetClip();
            }
            else if (layoutMode == ImageLayoutMode.FitToHeight)
            {
                g.SetClip(rect);
                Size newSize = new Size(rect.Height * image.Width / image.Height, rect.Height);
                g.DrawImage(image, new Rectangle(rect.Location, newSize));
                g.ResetClip();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Renders the specified HTML source on the specified area clipping if specified
        /// </summary>
        /// <param name="g">Device to draw</param>
        /// <param name="html">HTML source</param>
        /// <param name="area">Area where HTML should be drawn</param>
        /// <param name="clip">If true, it will only paint on the specified area</param>
        public static void Render(Graphics g, string html, RectangleF area, bool clip)
        {
            InitialContainer container = new InitialContainer(html);
            Region prevClip = g.Clip;

            if (clip) g.SetClip(area);

            container.SetBounds(area);
            container.MeasureBounds(g);
            container.Paint(g);

            if (clip) g.SetClip(prevClip, System.Drawing.Drawing2D.CombineMode.Replace);
        }
Ejemplo n.º 7
0
        public static void FillRoundedRectangle(Rectangle rectangle, GlassGradient gradient, bool isSunk, bool isGlass,
                                                Graphics graphics)
        {
            if (rectangle.Width == 0 || rectangle.Height == 0)
                return;

            var path = GetRoundedRectanglePath(rectangle);

            var activeGradient = isSunk
                                     ? new GlassGradient(gradient.Bottom, gradient.Top)
                                     : new GlassGradient(gradient.Top, gradient.Bottom);

            var brush = activeGradient.GetBrush(rectangle);
            graphics.FillPath(brush, path);
            brush.Dispose();

            if (isGlass)
            {
                graphics.SetClip(path);

                var glassRectangle = isSunk
                                         ? new Rectangle(new Point(rectangle.Left, rectangle.Height/2),
                                                         new Size(rectangle.Width, rectangle.Height/2))
                                         : new Rectangle(rectangle.Location,
                                                         new Size(rectangle.Width, rectangle.Height/2));
                var glassPath = GetRoundedRectanglePath(glassRectangle);
                Brush glassBrush = new LinearGradientBrush(glassRectangle, Color.Transparent,
                                                           Color.FromArgb(32, 255, 255, 255), 90.0f);

                graphics.FillPath(glassBrush, glassPath);

                glassBrush.Dispose();
                glassPath.Dispose();
            }
        }
Ejemplo n.º 8
0
            protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                // save graphics state to prevent artifacts in other paint operations in the grid
                var state = graphics.Save();

                if (!ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null)
                {
                    cachedGraphicsKey = graphics;
                    cachedGraphics    = new Graphics(new GraphicsHandler(graphics, dispose: false));
                }
                else
                {
                    ((GraphicsHandler)cachedGraphics.Handler).SetInitialState();
                }
                graphics.PixelOffsetMode = sd.Drawing2D.PixelOffsetMode.Half;
                graphics.SetClip(cellBounds);
                var color = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);

                graphics.FillRectangle(color, cellBounds);
                var args = new CellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value);

                Handler.Callback.OnPaint(Handler.Widget, args);
                graphics.ResetClip();
                graphics.Restore(state);
            }
Ejemplo n.º 9
0
        public void Draw(Graphics g)
        {
            g.Clear(BackgroundColor);

            g.SetClip(new Rectangle(0, 0, (int)RenderWidth, (int)RenderHeight));

            foreach (GDIObject obj in Objects)
            {
                obj.X -= CanvasX;
                obj.Y -= CanvasY;

                obj.Draw(g);
            }

            g.ResetClip();

            if (ShowGrid)
            {
                for (var x = 0; x < RenderWidth + CanvasX; x++)
                {
                    if (x % GridCellSize.X == 0)
                        g.DrawLine(GridColor, x - CanvasX, 0, x - CanvasX, RenderHeight);
                }

                for (var y = 0; y < RenderHeight + CanvasY; y++)
                {
                    if (y % GridCellSize.Y == 0)
                        g.DrawLine(GridColor, 0, y - CanvasY, RenderWidth, y - CanvasY);
                }
            }
        }
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR);
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            graphics.SmoothingMode = SmoothingMode.None;
            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.None;
            int halfWidth = rect.Width / 2;
            int halfHeight = rect.Height / 2;
            int newWidth = rect.Width / magnificationFactor;
            int newHeight = rect.Height / magnificationFactor;
            Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight);
            graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel);
            graphics.Restore(state);
        }
Ejemplo n.º 11
0
            protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts);

                var val = value as object[];
                var img = val[0] as sd.Image;

                if (img != null)
                {
                    if (paintParts.HasFlag(swf.DataGridViewPaintParts.Background))
                    {
                        using (var b = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor))
                        {
                            graphics.FillRectangle(b, new sd.Rectangle(cellBounds.X, cellBounds.Y, IconSize + IconPadding * 2, cellBounds.Height));
                        }
                    }

                    var container = graphics.BeginContainer();
                    graphics.SetClip(cellBounds);
                    if (paintParts.HasFlag(swf.DataGridViewPaintParts.Background))
                    {
                        using (var background = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor))
                            graphics.FillRectangle(background, cellBounds);
                    }
                    graphics.InterpolationMode = InterpolationMode;
                    graphics.DrawImage(img, new sd.Rectangle(cellBounds.X + IconPadding, cellBounds.Y + (cellBounds.Height - Math.Min(img.Height, cellBounds.Height)) / 2, IconSize, IconSize));
                    graphics.EndContainer(container);
                    cellBounds.X     += IconSize + IconPadding * 2;
                    cellBounds.Width -= IconSize + IconPadding * 2;
                }
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
Ejemplo n.º 12
0
        private void Render(System.Drawing.Graphics g)
        {
            if (!Visible)
            {
                return;
            }
            using (var b = new SolidBrush(BackColor))
            {
                g.FillRectangle(b, ClientRectangle);
            }
            var display = new Rectangle(DisplayRectangle.Location, DisplayRectangle.Size);

            if (TabPages.Count == 0)
            {
                display.Y += 21;
            }
            var border = SystemInformation.Border3DSize.Width;

            display.Inflate(border, border);
            g.DrawLine(SystemPens.ControlDark, display.X, display.Y, display.X + display.Width, display.Y);
            var clip = g.Clip;

            g.SetClip(new Rectangle(display.Left, ClientRectangle.Top, display.Width, ClientRectangle.Height));
            for (var i = 0; i < TabPages.Count; i++)
            {
                RenderTab(g, i);
            }
            g.Clip = clip;
        }
Ejemplo n.º 13
0
		public void Draw(Graphics graphics)
		{
			graphics.SetClip(parentGraph.ClientRectangle);

			Pen axisPen = new Pen(new SolidBrush(parentGraph.YAxisColor), 2F);
			axisPen.EndCap = LineCap.ArrowAnchor;

			RectangleF graphArea = parentGraph.GraphArea;

			graphics.DrawLine(axisPen,
							  graphArea.Left,
							  graphArea.Bottom,
							  graphArea.Left,
							  graphArea.Top);

			axisPen.Color = parentGraph.XAxisColor;
			axisPen.EndCap = LineCap.ArrowAnchor;

			graphics.DrawLine(axisPen,
							  graphArea.Left,
							  graphArea.Bottom,
							  graphArea.Right,
							  graphArea.Bottom);

			axisPen.Dispose();
		}
Ejemplo n.º 14
0
 public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
 {
     int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS);
     double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY);
     Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);
     if (applyRect.Width == 0 || applyRect.Height == 0)
     {
         return;
     }
     GraphicsState state = graphics.Save();
     if (Invert)
     {
         graphics.SetClip(applyRect);
         graphics.ExcludeClip(rect);
     }
     if (GDIplus.IsBlurPossible(blurRadius))
     {
         GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false);
     }
     else
     {
         using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect))
         {
             ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius);
             fastBitmap.DrawTo(graphics, applyRect);
         }
     }
     graphics.Restore(state);
     return;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Paints the entity using the given graphics object
        /// </summary>
        /// <param name="g"></param>
        public override void Paint(System.Drawing.Graphics g)
        {
            if (!Visible)
            {
                return;
            }

            //g.DrawRectangle(Pens.OrangeRed, Rectangle);
            GraphicsContainer cto = g.BeginContainer();

            g.SetClip(Shape.Rectangle);
            plusminus.Paint(g);
            header.Paint(g);
            if (!mCollapsed && mShowLines)
            {
                g.DrawLine(ArtPallet.FolderLinesPen, Rectangle.X + 7, plusminus.Rectangle.Bottom, Rectangle.X + 7, plusminus.Rectangle.Bottom + mEntries.Count * (constItemHeight + constItemSpacing));
            }
            int k = 1;

            foreach (IShapeMaterial material in mEntries)
            {
                material.Paint(g);
                if (!mCollapsed && mShowLines)
                {
                    g.DrawLine(ArtPallet.FolderLinesPen, Rectangle.X + 7, plusminus.Rectangle.Bottom + k * (constItemHeight + constItemSpacing), Rectangle.X + 16, plusminus.Rectangle.Bottom + k * (constItemHeight + constItemSpacing));
                    k++;
                }
            }
            g.EndContainer(cto);
        }
Ejemplo n.º 16
0
		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}
			GraphicsState state = graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) {
				Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
				for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++) {
					for (int x = fastBitmap.Left; x < fastBitmap.Right; x++) {
						Color color = fastBitmap.GetColorAt(x, y);
						color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B));
						fastBitmap.SetColorAt(x, y, color);
					}
				}
				fastBitmap.DrawTo(graphics, applyRect.Location);
			}
			graphics.Restore(state);
		}
Ejemplo n.º 17
0
        /// <summary>
        /// Draws the data of a tree node at the specified location.</summary>
        /// <param name="node">The tree control's node whose data is to be drawn</param>
        /// <param name="g">The current GDI+ graphics object</param>
        /// <param name="x">The x-coordinate of the upper-left corner of the node label</param>
        /// <param name="y">The y-coordinate of the upper-left corner of the node label</param>
        public override void DrawData(TreeControl.Node node, Graphics g, int x, int y)
        {
            var treeListControl = node.TreeControl as TreeListControl;

            ItemInfo info = new WinFormsItemInfo();
            m_itemView.GetInfo(node.Tag, info);
            if (info.Properties.Length ==0)
                return;

            Region oldClip = g.Clip;

            UpdateColumnWidths(node, info, g);
            int xOffset = treeListControl.TreeWidth;
            for (int i = 0; i < info.Properties.Length; ++i) 
            {
                var dataEditor = info.Properties[i] as DataEditor;
                if (dataEditor != null) // show object data details in columns
                {
                    if (TrackingEditor != null && (TrackingEditor.Owner == node.Tag) &&
                        (TrackingEditor.Name == dataEditor.Name))
                        dataEditor = TrackingEditor;
                    var clip = new Rectangle(xOffset, y, treeListControl.Columns[i].ActualWidth, treeListControl.GetRowHeight(node));
                    if (i == info.Properties.Length-1) // extends last column 
                        clip.Width = node.TreeControl.ActualClientSize.Width - xOffset;
                    g.SetClip(clip);
                    dataEditor.PaintValue(g, clip);
                }
                xOffset += treeListControl.Columns[i].ActualWidth;
            }

            g.Clip = oldClip;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Renders the key in the specified surface.
        /// </summary>
        /// <param name="g">The GDI+ surface to render on.</param>
        /// <param name="scrollCount">The number of times the direction has been scrolled within the timeout.</param>
        public void Render(Graphics g, int scrollCount)
        {
            var pressed = scrollCount > 0;
            var style = GlobalSettings.CurrentStyle.TryGetElementStyle<KeyStyle>(this.Id)
                            ?? GlobalSettings.CurrentStyle.DefaultKeyStyle;
            var defaultStyle = GlobalSettings.CurrentStyle.DefaultKeyStyle;
            var subStyle = pressed ? style?.Pressed ?? defaultStyle.Pressed : style?.Loose ?? defaultStyle.Loose;

            var text = pressed ? scrollCount.ToString() : this.Text;
            var txtSize = g.MeasureString(text, subStyle.Font);
            var txtPoint = new TPoint(
                this.TextPosition.X - (int)(txtSize.Width / 2),
                this.TextPosition.Y - (int)(txtSize.Height / 2));

            // Draw the background
            var backgroundBrush = this.GetBackgroundBrush(subStyle, pressed);
            g.FillPolygon(backgroundBrush, this.Boundaries.ConvertAll<Point>(x => x).ToArray());

            // Draw the text
            g.SetClip(this.GetBoundingBox());
            g.DrawString(text, subStyle.Font, new SolidBrush(subStyle.Text), (Point)txtPoint);
            g.ResetClip();

            // Draw the outline.
            if (subStyle.ShowOutline)
                g.DrawPolygon(new Pen(subStyle.Outline, 1), this.Boundaries.ConvertAll<Point>(x => x).ToArray());
        }
Ejemplo n.º 19
0
		//=========================================================================================
		internal void RenderView(Graphics g)
		{
			g.FillRectangle(SystemBrushes.Window, this.Body.ClientRectangle);

			if (this.Viewer.ShowMargin)
			{
				this.DrawMarginBackground(g);
				this.DrawLineIcons(g);
			}

			if (this.Viewer.ShowLineNumbers)
				this.DrawLineNumbers(g);

			//set the clipping region
			Rectangle r = this.Body.DisplayRectangle;
			r.X += this.Viewer.CharOffset - 1 + this.Viewer.MarginWidth;
			g.SetClip(r);

			this.DrawLinesBg(g);
			if (this.Viewer.HighlightCurrentLine && this.Body.Focused)
				this.DrawCurrentLineBackground(g);
			this.DrawSpansBackground(g);
			this.DrawSelectedTextBackground(g);
			this.DrawLinesOfDocument(this.Body.DisplayRectangle.Location, g);
		}
Ejemplo n.º 20
0
        protected override void  Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            Bitmap    estrellaBmp  = MSDNVideo.Tienda.Properties.Resources.Estrella;
            Rectangle rectEstrella = new Rectangle(cellBounds.X, cellBounds.Y + 2, (int)(estrellaBmp.Width * (cellBounds.Height - 4) / estrellaBmp.Height), cellBounds.Height - 4);
            int       i;
            int       widthValue;

            if (value == null)
            {
                widthValue = 0;
            }
            else
            {
                widthValue = (int)((double)((decimal)value) * cellBounds.Width / 10d);
            }

            graphics.FillRectangle(Brushes.White, cellBounds);
            graphics.SetClip(new Rectangle(cellBounds.X, cellBounds.Y, widthValue, cellBounds.Height));
            for (i = 0; i <= (int)(widthValue / rectEstrella.Width); i++)
            {
                graphics.DrawImage(estrellaBmp, rectEstrella, new Rectangle(0, 0, estrellaBmp.Width, estrellaBmp.Height), GraphicsUnit.Pixel);
                rectEstrella.X += rectEstrella.Width;
            }

            graphics.ResetClip();

            string valor;

            valor = String.Format("{0:F1}", value);
            SizeF sizeText = graphics.MeasureString(valor, cellStyle.Font);

            graphics.DrawString(valor, cellStyle.Font, Brushes.Black, new Rectangle(cellBounds.X + (int)((cellBounds.Width - sizeText.Width) / 2), cellBounds.Y + (int)((cellBounds.Height - sizeText.Height) / 2), (int)(sizeText.Width) + 1, (int)(sizeText.Height) + 1));

            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.Border);
        }
Ejemplo n.º 21
0
        public override void DrawRegionRepresentation(Graphics gc, Render.RenderParameter r, Render.IDrawVisitor drawMethods, PointD mousePosition)
        {
            if (m_Param.Path.PointCount > 0)
            {
                GraphicsPath fill = new GraphicsPath();
                RectangleF rect = m_Param.Path.GetBounds();
                PointD refPt = (PointD)rect.Location + ((PointD)rect.Size.ToPointF()) / 2;
                // this will draw beyond the shape's location
                for (double i = -rect.Height; i < rect.Height; i++)
                {
                    PointD pt1 = refPt + PointD.Orthogonal(m_Param.V) * i * drawMethods.Spacing(m_Param.C);
                    PointD pt2 = pt1 + m_Param.V * rect.Width * rect.Height;
                    PointD pt3 = pt1 - m_Param.V * rect.Width * rect.Height;

                    fill.StartFigure();
                    fill.AddLine((Point)pt2, (Point)pt3);

                }

                GraphicsContainer c = gc.BeginContainer();
                gc.SetClip((Tools.Model.VectorPath)m_Param.Path);
                gc.DrawPath(r.RegionGuides, fill);
                gc.EndContainer(c);

            }
        }
Ejemplo n.º 22
0
        protected override void OnPaint(System.Drawing.Graphics g)
        {
            var strSize    = g.MeasureString(this.Text, this.Font);
            var contentBox = new RectangleF(0, 0, this.Size.Width, this.Size.Height);

            var patch =
                this.pressed ? backgroundPressed9P
                : this.over ? backgroundOver9P
                : backgroundNormal9P;

            if (patch != null)
            {
                patch          = anim != null && anim.IsRunning() ? anim.GetCurrentFrame() : patch;
                lastDrawnPatch = patch;
                contentBox     = patch.GetContentBox(this.Size);
                patch.Paint(g, this.Size);
            }
            else
            {
                drawDefaultButton(g);
            }

            g.SetClip(contentBox, System.Drawing.Drawing2D.CombineMode.Intersect);
            g.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), contentBox.Width / 2 - strSize.Width / 2 + contentBox.Left, contentBox.Height / 2 - strSize.Height / 2 + contentBox.Top);
        }
Ejemplo n.º 23
0
 public System.Drawing.Bitmap SetCornerAlpha(System.Drawing.Bitmap pBit)
 {
     System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(pBit);
     new System.Drawing.SolidBrush(EdgeDisplay.alphaColor);
     System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
     System.Drawing.PointF[] array = new System.Drawing.PointF[4];
     array[0] = new System.Drawing.PointF(0f, 0f);
     array[1] = new System.Drawing.PointF(0f, (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)pBit.Height, (float)pBit.Height);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)this.subSize.Width, 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width + this.subSize.Height + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     array[0] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2), 0f);
     array[1] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 - pBit.Height), (float)pBit.Height);
     array[2] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 + pBit.Height + 1), (float)pBit.Height);
     array[3] = new System.Drawing.PointF((float)(this.subSize.Width * 2 + this.subSize.Height * 2 + 1), 0f);
     graphicsPath.ClearMarkers();
     graphicsPath.AddPolygon(array);
     graphics.SetClip(graphicsPath);
     graphics.Clear(System.Drawing.Color.Transparent);
     return(pBit);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Renders rectangle on canvas.
        /// </summary>
        /// <param name="g">Target graphics to render shape on.</param>
        /// <param name="bounds">Shape bounds.</param>
        public override void Paint(Graphics g, Rectangle bounds)
        {
            if (bounds.Width < 2 || bounds.Height < 2 || g == null || _Fill == null && _Border == null) return;

            GraphicsPath path = null;
            
            if (!_CornerRadius.IsZero)
            {
                path = DisplayHelp.GetRoundedRectanglePath(bounds, _CornerRadius.TopLeft, _CornerRadius.TopRight, 
                    _CornerRadius.BottomRight, _CornerRadius.BottomLeft);
            }

            if (_Fill != null)
            {
                Brush brush = _Fill.CreateBrush(bounds);
                if (brush != null)
                {
                    SmoothingMode sm = g.SmoothingMode;
                    if (brush is SolidBrush && path==null)
                        g.SmoothingMode = SmoothingMode.None;
                    if (path == null)
                        g.FillRectangle(brush, bounds);
                    else
                        g.FillPath(brush, path);
                    g.SmoothingMode = sm;
                    brush.Dispose();
                }
            }

            if (_Border != null)
            {
                Pen pen = _Border.CreatePen();
                if (pen != null)
                {
                    if (path == null)
                        g.DrawRectangle(pen, bounds);
                    else
                        g.DrawPath(pen, path);

                    pen.Dispose();
                }
            }

            Shape content = this.Content;
            if (content != null)
            {
                Rectangle contentBounds = Border.Deflate(bounds, _Border);
                Region oldClip = null;
                if (path != null && ClipToBounds)
                {
                    oldClip = g.Clip;
                    g.SetClip(path, CombineMode.Intersect);
                }
                content.Paint(g, contentBounds);
                if (oldClip != null) g.Clip = oldClip;
            }

            if (path != null) path.Dispose();
        }
Ejemplo n.º 25
0
 //填充矩形(包括边缘如x为0,跨度为10,填充0-9)
 public static void fillRect(Graphics g, int x, int y, int width, int height, Color color, Rect limitRect)
 {
     if (width <= 0 || height <= 0 || g == null) return;
     g.ResetTransform();
     g.SetClip(new Rectangle(x - 1, y - 1, width + 2, height + 2));
     if (limitRect != null)
     {
         Rectangle rect = limitRect.rect;
         if (rect.Width > 0 && rect.Height > 0)
         {
             g.SetClip(rect, CombineMode.Intersect);
         }
     }
     Brush myBrush = new SolidBrush(color);
     g.FillRectangle(myBrush, x, y, width, height);
     myBrush.Dispose();
 }
Ejemplo n.º 26
0
 private void SetClip(Graphics g)
 {
     Rectangle r = this.ClientRectangle;
     r.X++; r.Y++; r.Width -= 3; r.Height -= 3;
     using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
     {
         g.SetClip(rr);
     }
 }
Ejemplo n.º 27
0
        public override void Draw(Graphics g)
        {
            base.Draw(g);

            var bounds = g.ClipBounds;

            g.SetClip(new RectangleF(X + LineThickness, Y + LineThickness, Width - LineThickness, Height - LineThickness));

            foreach (GDIObject obj in Items)
            {
                obj.X += X + ScrollX;
                obj.Y += Y + ScrollY;

                obj.Draw(g);
            }

            g.SetClip(bounds);
        }
Ejemplo n.º 28
0
        private void PaintText(System.Drawing.Graphics graphics, System.Drawing.Rectangle drawBounds, bool rightToLeft)
        {
            if (string.IsNullOrEmpty(progressText))
            {
                return;
            }

            var tmpForeColor = HuiruiSoft.Utils.ColorUtils.ColorToGrayscale(this.ForeColor);
            var tmpBackColor = System.Drawing.Color.FromArgb(tmpForeColor.ToArgb( ) ^ 0x20FFFFFF);

            if (!HuiruiSoft.Win32.NativeMethods.IsUnix( ))
            {
                int x      = drawBounds.X;
                int y      = drawBounds.Y;
                int width  = drawBounds.Width;
                int height = drawBounds.Height;

                var tmpGlowBounds = drawBounds;
                tmpGlowBounds.Width = TextRenderer.MeasureText(graphics, progressText, this.Font).Width;
                tmpGlowBounds.X     = (width - tmpGlowBounds.Width) / 2 + x;
                tmpGlowBounds.Inflate(tmpGlowBounds.Width / 2, tmpGlowBounds.Height / 2);

                using (var tmpGlowPath = new GraphicsPath( ))
                {
                    tmpGlowPath.AddEllipse(tmpGlowBounds);

                    using (var tmpGlowBrush = new PathGradientBrush(tmpGlowPath))
                    {
                        tmpGlowBrush.CenterPoint    = new PointF(width / 2.0f + x, height / 2.0f + y);
                        tmpGlowBrush.CenterColor    = tmpBackColor;
                        tmpGlowBrush.SurroundColors = new System.Drawing.Color[] { Color.Transparent };

                        var tmpOrgClip = graphics.Clip;
                        graphics.SetClip(drawBounds);
                        graphics.FillPath(tmpGlowBrush, tmpGlowPath);
                        graphics.Clip = tmpOrgClip;
                    }
                }
            }

            using (var tmpSolidBrush = new SolidBrush(tmpForeColor))
            {
                var tmpFormatFlags = (StringFormatFlags.FitBlackBox | StringFormatFlags.NoClip);
                if (rightToLeft)
                {
                    tmpFormatFlags |= StringFormatFlags.DirectionRightToLeft;
                }

                using (var tmpStringFormat = new StringFormat(tmpFormatFlags))
                {
                    tmpStringFormat.Alignment     = StringAlignment.Center;
                    tmpStringFormat.LineAlignment = StringAlignment.Center;
                    graphics.DrawString(progressText, this.Font, tmpSolidBrush, new RectangleF(drawBounds.X, drawBounds.Y, drawBounds.Width, drawBounds.Height), tmpStringFormat);
                }
            }
        }
Ejemplo n.º 29
0
        protected override void PaintRestore(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled)
        {
            //SmoothingMode sm = g.SmoothingMode;
            //g.SmoothingMode = SmoothingMode.Default;
            
            Size s = new Size(12, 11);
            Rectangle rm = GetSignRect(r, s);
            Region oldClip = g.Clip;

            using (Brush fill = DisplayHelp.CreateBrush(rm, ct.Foreground))
            {
                using (Pen pen = new Pen(ct.DarkShade))
                {
                    using (GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(new Rectangle(rm.X + 5, rm.Y, 8, 8), 1))
                    {
                        Rectangle inner = new Rectangle(rm.X + 7, rm.Y + 4, 4, 2);
                        g.SetClip(inner, CombineMode.Exclude);
                        g.SetClip(new Rectangle(rm.X, rm.Y + 3, 8, 8), CombineMode.Exclude);
                        g.FillPath(fill, path);
                        g.DrawPath(pen, path);
                        g.ResetClip();
                        g.DrawRectangle(pen, inner);
                    }
                    using (GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(new Rectangle(rm.X, rm.Y + 3, 8, 8), 1))
                    {
                        Rectangle inner = new Rectangle(rm.X + 2, rm.Y + 7, 4, 2);
                        g.SetClip(inner, CombineMode.Exclude);
                        g.FillPath(fill, path);
                        g.DrawPath(pen, path);
                        g.ResetClip();
                        g.DrawRectangle(pen, inner);
                    }
                }
            }
            if (oldClip != null)
            {
                g.Clip = oldClip;
                oldClip.Dispose();
            }
            //g.SmoothingMode = sm;
        }
Ejemplo n.º 30
0
        public void DrawHover(Graphics graphics, Rectangle bounds, double hoverDone)
        {
            using (Bitmap b = new Bitmap(mBackgroundImage, bounds.Size))
                graphics.DrawImage(b, bounds.Location);

            var path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddPie(bounds.X, bounds.Y, bounds.Width, bounds.Height, -90f, (float) (360 * hoverDone));
            graphics.SetClip(path);
            using (Bitmap b = new Bitmap(mImage, bounds.Size))
                graphics.DrawImage(b, bounds.Location);
            graphics.ResetClip();
        }
Ejemplo n.º 31
0
            protected override void Render(RectangleF sourceBounds, Matrix transform, Graphics g)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.Transform = transform;
                sourceBounds.Inflate(1, 1); // allow for pen widths
                g.SetClip(sourceBounds);

                foreach (IPrintingAdapter printingAdapter in m_viewingContext.Control.AsAll<IPrintingAdapter>())
                    printingAdapter.Print(this, g);
            }
Ejemplo n.º 32
0
 public override System.Drawing.Bitmap GetNext()
 {
     if (this.nowState == MarqueeDisplayState.First)
     {
         this.nowPositionF -= this.step;
         if (this.nowPositionF > (float)((this.newBitmap.Height + this.newBitmap.Width) / 2))
         {
             this.nowState = MarqueeDisplayState.Stay;
         }
         this.nowPosition = (int)this.nowPositionF;
         this.getPoint1(this.nowPosition);
         this.getPoint2(this.nowPosition);
         this.getPoint3(this.nowPosition);
         this.getPoint4(this.nowPosition);
         System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(this.newBitmap);
         System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
         System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         graphicsPath.AddPolygon(this.pa1);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa2);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa3);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         graphicsPath.ClearMarkers();
         graphicsPath.AddPolygon(this.pa4);
         graphics.SetClip(graphicsPath);
         graphics.Clear(System.Drawing.Color.Black);
         if (this.nowPositionF <= 0f)
         {
             this.nowState = MarqueeDisplayState.Second;
         }
         return(bitmap);
     }
     return(null);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Paints the entity using the given graphics object
        /// </summary>
        /// <param name="g"></param>
        public override void Paint(Graphics g)
        {
            if(!Visible)
                return;

            if(mIcon != null)
            {
                GraphicsContainer cto = g.BeginContainer();
                g.SetClip(Shape.Rectangle);
                g.DrawImage(mIcon, Rectangle);
                g.EndContainer(cto);
            }
        }
Ejemplo n.º 34
0
            protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                if (!object.ReferenceEquals(cachedGraphicsKey, graphics) ||
                    cachedGraphics == null)
                {
                    cachedGraphicsKey = graphics;
                    cachedGraphics    = new Graphics(Handler.Generator, new GraphicsHandler(graphics, shouldDisposeGraphics: false));
                }

                if (Handler.Widget.PaintHandler != null)
                {
                    var b = graphics.ClipBounds;
                    graphics.SetClip(clipBounds);
                    Handler.Widget.PaintHandler(new DrawableCellPaintArgs
                    {
                        Graphics   = cachedGraphics,
                        CellBounds = new RectangleF(cellBounds.ToEto()),
                        Item       = value,
                        CellState  = cellState.ToEto(),
                    });
                    graphics.SetClip(b);                     // restore
                }
            }
Ejemplo n.º 35
0
        public void Draw(System.Windows.Forms.ListViewItem item, System.Drawing.Graphics g, Rectangle boundRect)
        {
            if (!IsHandled(item))
            {
                return;
            }

            ListView listView = item.ListView;

            RichText.RichText text        = (RichText.RichText)myItems[item];
            Rectangle         rect        = CalculateItemRectangle(item, boundRect);
            Rectangle         contentRect = CalculateContentRectangle(item, g, rect);

            // Center content vertically
            if (contentRect.Height < rect.Height)
            {
                int topOffset = (rect.Height - contentRect.Height) / 2;
                contentRect.Y += topOffset;
            }

            g.FillRectangle(new SolidBrush(listView.BackColor), rect);

            if (item.Selected)
            {
                Color backgroundColor = Colors.ListSelectionBackColor(listView.Focused);

                text = (RichText.RichText)text.Clone();

                g.FillRectangle(new SolidBrush(backgroundColor), rect);
                text.SetColors(SystemColors.HighlightText, backgroundColor);
            }

            g.SetClip(rect);

            IntPtr hdc = g.GetHdc();

            try
            {
                text.Draw(hdc, contentRect);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }

            if (item.Selected && listView.Focused)
            {
                DrawDottedRectangle(g, rect);
            }
        }
Ejemplo n.º 36
0
            protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                if (!object.ReferenceEquals(cachedGraphicsKey, graphics) ||
                    cachedGraphics == null)
                {
                    cachedGraphicsKey = graphics;
                    cachedGraphics    = new Graphics(new GraphicsHandler(graphics, shouldDisposeGraphics: false));
                }

                graphics.SetClip(cellBounds);
                var args = new DrawableCellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value);

                Handler.Callback.OnPaint(Handler.Widget, args);
                graphics.ResetClip();
            }
Ejemplo n.º 37
0
 public static void fillRect(Graphics g, int x, int y, int width, int height, int pColor, int alpha, Rect limitRect)
 {
     Color color = Color.FromArgb(alpha, (pColor >> 16) & 0xFF, (pColor >> 8) & 0xFF, (pColor >> 0) & 0xFF);
     if (width <= 0 || height <= 0 || g == null) return;
     g.SetClip(new Rectangle(x - 1, y - 1, width + 2, height + 2));
     if (limitRect != null)
     {
         Rectangle rect = limitRect.rect;
         if (rect.Width > 0 && rect.Height > 0)
         {
             g.SetClip(rect, CombineMode.Intersect);
         }
     }
     Brush myBrush = new SolidBrush(color);
     g.FillRectangle(myBrush, x, y, width, height);
     myBrush.Dispose();
 }
Ejemplo n.º 38
0
    public static void Paint(
        Graphics g,
        RectangleF area,
        float horizontalSpacing,
        float verticalSpacing,
        float penWidth) {
      //ControlPaint.DrawGrid(
      //    g,
      //    area,
      //    new Size(20, 20),
      //    Color.Wheat);

      //g.SmoothingMode = SmoothingMode.HighQuality;
      //g.CompositingQuality = CompositingQuality.HighQuality;
      //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
      g.SetClip(area);
      float sideLength = Math.Min(area.Width, area.Height);
      float horizSpacing = sideLength / horizontalSpacing;
      float vertSpacing = sideLength / verticalSpacing;

      Pen majorPen = new Pen(Color.DarkGray);
      majorPen.Width = penWidth;
      majorPen.DashStyle = DashStyle.Dot;

      float top = area.Top;  // The top y coord.
      float bottom = area.Bottom;  // The bottom y coord.
      float left = area.Left;  // The left y coord.
      float right = area.Right;  // The right y coord.
      PointF p1;  // The starting point for the grid line.
      PointF p2;  // The end point for the grid line.

      // Draw the horizontal lines, starting at the top.
      for (float i = top; i <= bottom; i += horizontalSpacing) {
        p1 = new PointF(left, i);
        p2 = new PointF(right, i);
        g.DrawLine(majorPen, p1, p2);
      }

      // Draw the major vertical lines, starting at the left edge.
      for (float i = left; i <= right; i += verticalSpacing) {
        p1 = new PointF(i, top);
        p2 = new PointF(i, bottom);
        g.DrawLine(majorPen, p1, p2);
      }
      g.ResetClip();
    }
Ejemplo n.º 39
0
        /// <summary>
        /// Draw the axis lines.
        /// </summary>
        /// <param name="graphics">Reference to the GDI+ drawing surface.</param>
		public void Draw(Graphics graphics)
		{
			graphics.SetClip(m_ParentGraph.ClientRectangle);

			// Y axis.
			using (Pen axisPen = new Pen(new SolidBrush(m_ParentGraph.YAxisColor), 2F))
			{
				// Set the cap style used at the end of the line.
				axisPen.EndCap = LineCap.ArrowAnchor;
				RectangleF graphArea = m_ParentGraph.GraphArea;
				graphics.DrawLine(axisPen, graphArea.Left, graphArea.Bottom, graphArea.Left, graphArea.Top);

				// X axis.
				axisPen.Color = m_ParentGraph.XAxisColor;
				axisPen.EndCap = LineCap.ArrowAnchor;
				graphics.DrawLine(axisPen, graphArea.Left, graphArea.Bottom, graphArea.Right, graphArea.Bottom);
			}
		}
Ejemplo n.º 40
0
        protected override void PaintMaximize(Graphics g, Rectangle r, Office2007SystemButtonStateColorTable ct, bool isEnabled)
        {
            Size s = new Size(10, 10);
            Rectangle rm = GetSignRect(r, s);
            Region oldClip = g.Clip;

            Rectangle inner = new Rectangle(rm.X + 1, rm.Y + 3, ct.DarkShade.IsEmpty ? 8 : 7, ct.DarkShade.IsEmpty ? 6 : 5);
            g.SetClip(inner, CombineMode.Exclude);
            if(isEnabled)
                DisplayHelp.FillRectangle(g, rm, ct.Foreground);
            else
                DisplayHelp.FillRectangle(g, rm, GetDisabledColor(ct.Foreground.Start), GetDisabledColor(ct.Foreground.End), ct.Foreground.GradientAngle);

            if (oldClip != null)
            {
                g.Clip = oldClip;
                oldClip.Dispose();
            }
        }
Ejemplo n.º 41
0
        /// <summary>
        /// 重新绘制本区域内的内容
        /// </summary>
        /// <param name="rect">相对当前屏幕的坐标矩形</param>
        public void paintArea(GDI.Rectangle rect)
        {
            if (rect.Height == 0 || rect.Width == 0)
            {
                return;
            }

            GDI.Drawing2D.GraphicsState state = g.Save();
            g.SetClip(rect);
            // 开始画图吧

            double iOffsetX = rect.X;
            int    iColumn  = GetCellColumn(ref iOffsetX);

            if (iColumn == -1)
            {
                g.Restore(state);
                return;
            }

            GB_GridView.CellPaintEventArgs e = new GB_GridView.CellPaintEventArgs();
            g.FillRectangle(m_background, rect);
            double iColumnWidth = rect.X - iOffsetX;

            for (int j = iColumn; j < Columns.Count; ++j)
            {
                if (iColumnWidth > ActualWidth)
                {
                    break; // 说明这一行画完了,开始画下一行吧
                }
                e.Bounds      = new GDI.Rectangle((int)iColumnWidth, 0, (int)Columns[j].Width, m_bufferedBmp.PixelHeight);
                iColumnWidth += Columns[j].Width;
                e.ColumnIndex = j;
                e.RowIndex    = -1;
                e.States      = GB_GridView.GridViewElementStates.Visible;
                e.Graphics    = g;
                e.Value       = Columns[j].Header.ToString();
                DefaultPaintCell(e);
            }


            g.Restore(state);
        }
Ejemplo n.º 42
0
            protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                Handler.Paint(graphics, clipBounds, ref cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, ref paintParts);

                var val = value as object[];
                var img = val[0] as sd.Image;

                if (img != null)
                {
                    var container = graphics.BeginContainer();
                    graphics.SetClip(cellBounds);
                    graphics.InterpolationMode = InterpolationMode;
                    graphics.DrawImage(img, new sd.Rectangle(cellBounds.X + IconPadding, cellBounds.Y + (cellBounds.Height - Math.Min(img.Height, cellBounds.Height)) / 2, IconSize, IconSize));
                    graphics.EndContainer(container);
                    cellBounds.X     += IconSize + IconPadding * 2;
                    cellBounds.Width -= IconSize + IconPadding * 2;
                }
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
Ejemplo n.º 43
0
		/// <summary>
		/// Implements the Apply code for the Brightness Filet
		/// </summary>
		/// <param name="graphics"></param>
		/// <param name="applyBitmap"></param>
		/// <param name="rect"></param>
		/// <param name="renderMode"></param>
		public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) {
			Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

			if (applyRect.Width == 0 || applyRect.Height == 0) {
				// nothing to do
				return;
			}

			GraphicsState state =  graphics.Save();
			if (Invert) {
				graphics.SetClip(applyRect);
				graphics.ExcludeClip(rect);
			}
			float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS);
			using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) {
				graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
			}
			graphics.Restore(state);
		}
Ejemplo n.º 44
0
		public void Draw(Graphics graphics)
		{
			Pen graphAreaPen = new Pen(parentGraph.GridlineColor);
			graphAreaPen.DashStyle = DashStyle.Dash;

			Brush graphAreaBrush = new SolidBrush(parentGraph.GraphAreaColor);

			graphics.FillRectangle(graphAreaBrush, parentGraph.GraphArea);
			graphics.DrawRectangle(graphAreaPen, parentGraph.GraphArea);

			if ((parentGraph.Gridlines & GridStyles.Horizontal) == GridStyles.Horizontal)
			{
				graphics.SetClip(parentGraph.GraphArea);

				int gridSize = parentGraph.GraphArea.Height / parentGraph.GraduationsY;
				for (int i = 0;i < parentGraph.GraphArea.Height;i += gridSize)
				{
					graphics.DrawLine(graphAreaPen,
									  parentGraph.GraphArea.Left,
									  parentGraph.GraphArea.Top + i,
									  parentGraph.GraphArea.Right,
									  parentGraph.GraphArea.Top + i);
				}
			}

			if ((parentGraph.Gridlines & GridStyles.Vertical) == GridStyles.Vertical)
			{
				int gridSize = parentGraph.GraphArea.Width / parentGraph.GraduationsX;

				for (int i = 0;i < parentGraph.GraphArea.Width;i += gridSize)
				{
					graphics.DrawLine(graphAreaPen,
									  parentGraph.GraphArea.Left + i,
									  parentGraph.GraphArea.Bottom,
									  parentGraph.GraphArea.Left + i,
									  parentGraph.GraphArea.Top);
				}
			}

			graphAreaPen.Dispose();
			graphAreaBrush.Dispose();
		}
Ejemplo n.º 45
0
        void PinPanelPaint(object sender, PaintEventArgs e)
        {
            if (FVisiblePins == null)
            {
                return;
            }

            FVisiblePins.Sort(delegate(TBasePin p1, TBasePin p2) { return((p1 as TBasePin).Order.CompareTo((p2 as TBasePin).Order)); });

            System.Drawing.Graphics g = e.Graphics;

            //mark current slice
            Brush     bgray = new System.Drawing.SolidBrush(Color.Gray);
            Rectangle r     = new Rectangle(0, 0, 0, 0);

            r.Location = new Point(FTargetPin * FPinWidth, (FTargetSlice + 1) * FSliceHeight);
            r.Width    = FPinWidth;
            r.Height   = FSliceHeight + 1;
            g.FillRectangle(bgray, r);

            //draw inputs
            Font  f      = new Font("Lucida Sans", 8);
            Brush bblack = new System.Drawing.SolidBrush(Color.Black);
            Pen   p      = new Pen(Color.Black);

            int idx = 0;

            foreach (TBasePin pin in FVisiblePins)
            {
                r.X      = idx * FPinWidth;
                r.Y      = 0;
                r.Width  = FPinWidth;
                r.Height = this.ClientRectangle.Height - 1;

                g.ResetClip();
                g.DrawRectangle(p, r);

                g.SetClip(r);
                pin.Draw(g, f, bblack, p, r);
                idx++;
            }
        }
Ejemplo n.º 46
0
            public bool SetClip(Graphics g, Window win)
            {
                Rectangle rc = new Rectangle(Left + win.Left, Top + win.Top, Width + 1, Height + 1);

                if (rc.Left < win.Left) rc.X = win.Left;
                if (rc.Top < win.Top) rc.Y = win.Top;

                if (rc.Left + rc.Width >= win.Left + win.Width) rc.Width = win.Left + win.Width - rc.Left;
                if (rc.Top + rc.Height >= win.Top + win.Height) rc.Height = win.Top + win.Height - rc.Top;

                if (rc.Width > 0 && rc.Height > 0)
                {
                    g.SetClip(rc);
                    return true;
                }
                else
                {
                    return false;
                }
            }
Ejemplo n.º 47
0
            protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts)
            {
                // save graphics state to prevent artifacts in other paint operations in the grid
                var state = graphics.Save();

                if (!object.ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null)
                {
                    cachedGraphicsKey = graphics;
                    cachedGraphics    = new Graphics(new GraphicsHandler(graphics, dispose: false));
                }
                else
                {
                    ((GraphicsHandler)cachedGraphics.Handler).SetInitialState();
                }
                graphics.SetClip(cellBounds);
#pragma warning disable 618
                var args = new DrawableCellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value);
                Handler.Callback.OnPaint(Handler.Widget, args);
#pragma warning restore 618
                graphics.ResetClip();
                graphics.Restore(state);
            }
Ejemplo n.º 48
0
        private static void MergeBitmaps(Bitmap bitmapFore, Bitmap bitmapBack)
        {
            // Define output polygon and coverage rectangle
            var curvePoints = new Point[] {
                new Point(833, 278), new Point(1876, 525),
                new Point(1876, 837), new Point(833, 830)
            };
            var outRect = new Rectangle(833, 278, 1043, 559);

            // Create clipping region from points
            System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
            clipPath.AddPolygon(curvePoints);

            try
            {
                Bitmap imgB = bitmapBack;
                Bitmap imgF = bitmapFore;
                Bitmap m    = new Bitmap(bitmapBack);
                System.Drawing.Graphics myGraphic = System.Drawing.Graphics.FromImage(m);

                myGraphic.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                myGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                myGraphic.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                // Draw foreground image into clipping region
                myGraphic.SetClip(clipPath, System.Drawing.Drawing2D.CombineMode.Replace);
                myGraphic.DrawImage(imgF, outRect);
                myGraphic.ResetClip();

                myGraphic.Save();
                m.Save(@"test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
Ejemplo n.º 49
0
        /// <summary>
        /// Override OnPaint method
        /// </summary>
        /// <param name="e">paint event argument</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;

            int hh = (int)Math.Round(Height / 2f);

            GraphicsToolkit.FillTriangle(g, 8, new Point(10, hh), GraphicsToolkit.TriangleDirection.Left,
                                         viewScroll > 0 ? SystemPens.WindowText : SystemPens.GrayText);

            int max = this.maxWidth - this.ClientRectangle.Width + rightPadding + 10;

            GraphicsToolkit.FillTriangle(g, 8, new Point(20, hh), GraphicsToolkit.TriangleDirection.Right,
                                         viewScroll < max ? SystemPens.WindowText : SystemPens.GrayText);

            var controlStyle = this.grid.ControlStyle;

            var borderPen        = this.resourceManager.GetPen(controlStyle[ControlAppearanceColors.SheetTabBorder]);
            var defaultTextBrush = this.resourceManager.GetBrush(this.ForeColor);

            Rectangle rect = new Rectangle(leftPadding, 0, ClientRectangle.Width - 4, ClientRectangle.Height - 2);

            #region Border
            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
            {
                switch (this.Position)
                {
                default:
                case SheetTabControlPosition.Top:
                    g.DrawLine(borderPen, 0, rect.Bottom - 1,
                               ClientRectangle.Right, rect.Bottom - 1);
                    break;

                case SheetTabControlPosition.Bottom:
                    g.DrawLine(borderPen, 0, rect.Top, ClientRectangle.Right, rect.Top);
                    break;
                }
            }
            #endregion

            g.SetClip(new Rectangle(ClientRectangle.Left + leftPadding, ClientRectangle.Top,
                                    ClientRectangle.Width - leftPadding - rightPadding, ClientRectangle.Height));

            g.TranslateTransform(-this.viewScroll, 0);

            using (var sf = new StringFormat(StringFormat.GenericTypographic)
            {
                Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center,
            })
            {
                int textTopPadding = (this.ClientRectangle.Height - this.Font.Height) / 2;

                #region Unselected items

                for (int i = 0; i < tabs.Count; i++)
                {
                    var tab = this.tabs[i];
                    rect = tab.Bounds;

                    if (i != selectedIndex)
                    {
                        if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                        {
                            using (var bb = new SolidBrush(tab.BackgroundColor))
                            {
                                g.FillRectangle(bb, rect);
                            }
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, defaultTextBrush, rect, sf);
                        }

                        if (i > 0)
                        {
                            g.DrawLine(SystemPens.ControlDark, rect.Left, rect.Top + 4, rect.Left, rect.Bottom - 4);
                        }
                    }

                    if (rect.Left > maxWidth)
                    {
                        break;
                    }
                }

                #endregion

                #region Selected item

                if (this.selectedIndex >= 0 && this.selectedIndex < this.tabs.Count)
                {
                    var tab = this.tabs[this.selectedIndex];
                    rect = tab.Bounds;

                    if (rect.Right > this.viewScroll ||
                        rect.Left < this.maxWidth - this.viewScroll)
                    {
                        int x = rect.Left, x2 = rect.Right, y = 0, y2 = 0;

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                        {
                            if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                            {
                                x++; x2--;
                            }

                            switch (this.Position)
                            {
                            default:
                            case SheetTabControlPosition.Top:
                                y = rect.Top; y2 = rect.Bottom;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y++; y2--;
                                }

                                break;

                            case SheetTabControlPosition.Bottom:
                                y = rect.Bottom - 1; y2 = rect.Top;

                                if (this.BorderStyle == SheetTabBorderStyle.SplitRouned)
                                {
                                    y--; y2++;
                                }

                                break;
                            }

                            // left and right
                            g.DrawLine(borderPen, rect.Left, y, rect.Left, y2);
                            g.DrawLine(borderPen, rect.Right, y, rect.Right, y2);
                        }

                        Brush selectedBackBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabSelected]);
                        Brush selectedTextBrush = this.resourceManager.GetBrush(controlStyle[ControlAppearanceColors.SheetTabText]);

                        // top or bottom
                        switch (this.Position)
                        {
                        default:
                        case SheetTabControlPosition.Top:
                            var bgrectTop = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectTop);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectTop);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Top, x2, rect.Top);
                            }
                            break;

                        case SheetTabControlPosition.Bottom:

                            var bgrectBottom = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 1, rect.Height - 1);

                            if (!tab.BackgroundColor.IsEmpty && tab.BackgroundColor.A > 0)
                            {
                                using (var bb = new SolidBrush(tab.BackgroundColor))
                                {
                                    g.FillRectangle(bb, bgrectBottom);
                                }
                            }
                            else
                            {
                                g.FillRectangle(selectedBackBrush, bgrectBottom);
                            }

                            if (this.BorderStyle != SheetTabBorderStyle.NoBorder)
                            {
                                g.DrawLine(borderPen, x, rect.Bottom - 1, x2, rect.Bottom - 1);
                            }
                            break;
                        }

                        if (this.BorderStyle != SheetTabBorderStyle.NoBorder && Shadow)
                        {
                            g.DrawLine(borderPen, rect.Right + 1, rect.Top + 2, rect.Right + 1, rect.Bottom - 1);
                        }

                        if (!tab.ForegroundColor.IsEmpty && tab.ForegroundColor.A > 0)
                        {
                            using (var fb = new SolidBrush(tab.ForegroundColor))
                            {
                                g.DrawString(tab.Title, this.Font, fb, rect, sf);
                            }
                        }
                        else
                        {
                            g.DrawString(tab.Title, this.Font, selectedTextBrush, rect, sf);
                        }
                    }
                }

                #endregion                 // Selected item
            }

            g.ResetClip();
            g.ResetTransform();

            if (this.NewButtonVisible)
            {
                g.DrawImage(addButtonHover ? newButtonImage : newButtonDisableImage,
                            new Rectangle(this.ClientRectangle.Width - 28, (this.ClientRectangle.Height - 16) / 2, 16, 16));
            }

            for (int i = 4; i < this.ClientRectangle.Height - 4; i += 4)
            {
                g.FillRectangle(SystemBrushes.ControlDark, new Rectangle(this.ClientRectangle.Right - 5, i, 2, 2));
            }

            if (this.movingHoverIndex >= 0 && this.movingHoverIndex <= this.tabs.Count &&
                this.movingHoverIndex != this.movingStartIndex)
            {
                Rectangle itemRect = GetItemBounds(this.movingHoverIndex >= this.tabs.Count ?
                                                   this.tabs.Count - 1 : this.movingHoverIndex);

                GraphicsToolkit.FillTriangle(g, 8, new Point(
                                                 (this.movingHoverIndex >= this.tabs.Count ? itemRect.Right : itemRect.Left) - this.viewScroll,
                                                 itemRect.Top + 4), GraphicsToolkit.TriangleDirection.Up);
            }

            base.OnPaint(e);
        }
Ejemplo n.º 50
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string imgSourcePath  = @"D:\_Working\01.jpg";
            string imgTarget1Path = @"D:\_Working\01_crop1.png";
            string imgTarget2Path = @"D:\_Working\01_crop2.png";
            string imgTarget3Path = @"D:\_Working\01_crop3.png";

            if (System.IO.File.Exists(imgTarget1Path))
            {
                System.IO.File.Delete(imgTarget1Path);
            }
            if (System.IO.File.Exists(imgTarget2Path))
            {
                System.IO.File.Delete(imgTarget2Path);
            }
            if (System.IO.File.Exists(imgTarget3Path))
            {
                System.IO.File.Delete(imgTarget3Path);
            }

            System.Drawing.Image     imgSource  = System.Drawing.Image.FromFile(imgSourcePath);
            System.Drawing.Rectangle cropArea   = new System.Drawing.Rectangle(100, 100, 200, 200);
            System.Drawing.Bitmap    imgTarget1 = new System.Drawing.Bitmap(200, 200);
            System.Drawing.Bitmap    imgTarget2 = new System.Drawing.Bitmap(200, 200);
            System.Drawing.Bitmap    imgTarget3 = new System.Drawing.Bitmap(200, 200);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgTarget1))
            {
                //Graphic.SmoothingMode = SmoothingMode.AntiAlias;
                //Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
                //Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
                //Graphic.DrawImage(OriginalImage, new SD.Rectangle(0, 0, Width, Height), X, Y, Width, Height, SD.GraphicsUnit.Pixel);
                //MemoryStream ms = new MemoryStream();
                //bmp.Save(ms, OriginalImage.RawFormat);

                g.DrawImage(imgSource, new Rectangle(0, 0, imgTarget1.Width, imgTarget1.Height), cropArea, GraphicsUnit.Pixel);
                imgTarget1.Save(imgTarget1Path, System.Drawing.Imaging.ImageFormat.Png);
            }

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgTarget2))
            {
                System.Drawing.Drawing2D.GraphicsPath path = DrawRectangleRadius(0, 0, 200, 200, 5, 6, 6, 7);
                g.SetClip(path, System.Drawing.Drawing2D.CombineMode.Replace);
                g.DrawImage(imgSource, new Rectangle(0, 0, imgTarget2.Width, imgTarget2.Height), cropArea, GraphicsUnit.Pixel);

                imgTarget2.Save(imgTarget2Path, System.Drawing.Imaging.ImageFormat.Png);
            }

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgTarget3))
            {
                System.Drawing.Drawing2D.GraphicsPath path = DrawEllipse(0, 0, 50, 100);
                g.SetClip(path, System.Drawing.Drawing2D.CombineMode.Replace);
                g.DrawImage(imgSource, new Rectangle(0, 0, imgTarget3.Width, imgTarget3.Height), cropArea, GraphicsUnit.Pixel);

                imgTarget3.Save(imgTarget3Path, System.Drawing.Imaging.ImageFormat.Png);
            }


            //// Crop Image Here & Save
            //string fileName = Path.GetFileName(imgUpload.ImageUrl);
            //string filePath = Path.Combine(Server.MapPath("~/UploadImages"), fileName);
            //string cropFileName = "";
            //string cropFilePath = "";
            //if (File.Exists(filePath))
            //{
            //    System.Drawing.Image orgImg = System.Drawing.Image.FromFile(filePath);
            //    Rectangle CropArea = new Rectangle(Convert.ToInt32(X.Value), Convert.ToInt32(Y.Value), Convert.ToInt32(W.Value), Convert.ToInt32(H.Value));
            //    try
            //    {
            //        Bitmap bitMap = new Bitmap(CropArea.Width, CropArea.Height);
            //        using (Graphics g = Graphics.FromImage(bitMap))
            //        {
            //            g.DrawImage(orgImg, new Rectangle(0, 0, bitMap.Width, bitMap.Height), CropArea, GraphicsUnit.Pixel);
            //            //g.DrawImage()

            //            //g.FillClosedCurve
            //        }

            //        cropFileName = "crop_" + fileName;
            //        cropFilePath = Path.Combine(Server.MapPath("~/UploadImages"), cropFileName);
            //        bitMap.Save(cropFilePath);
            //        Response.Redirect("~/UploadImages/" + cropFileName, false);
            //    }
            //    catch (Exception ex)
            //    {
            //        throw;
            //    }
            //}
        }
Ejemplo n.º 51
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            string text  = context.Request["code"];
            string text2 = context.Request["Combin"];
            string text3 = context.Request["Logo"];

            if (!string.IsNullOrEmpty(text))
            {
                System.Drawing.Image image = new QRCodeEncoder
                {
                    QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE,
                    QRCodeScale        = 6,
                    QRCodeVersion      = 5,
                    QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M
                }.Encode(text);
                System.Drawing.Image image2 = null;
                if (!string.IsNullOrEmpty(text3))
                {
                    if (!text3.ToLower().StartsWith("http") && System.IO.File.Exists(context.Server.MapPath(text3)))
                    {
                        image2 = System.Drawing.Image.FromFile(context.Server.MapPath(text3));
                    }
                    else if (text3.ToLower().StartsWith("http"))
                    {
                        image2 = this.getNetImg(text3);
                    }
                }
                System.Drawing.Bitmap bitmap = null;
                if (image2 != null)
                {
                    bitmap = new System.Drawing.Bitmap(200, 200);
                    System.Drawing.Drawing2D.GraphicsPath clip = CreatQRCode.CreateRoundedRectanglePath(new System.Drawing.Rectangle(0, 0, 200, 200), 20);
                    using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        graphics.SetClip(clip);
                        graphics.Clear(System.Drawing.Color.White);
                        clip = CreatQRCode.CreateRoundedRectanglePath(new System.Drawing.Rectangle(14, 14, 172, 172), 14);
                        graphics.SetClip(clip);
                        graphics.DrawImage(image2, 0, 0, 200, 200);
                    }
                    image2.Dispose();
                }
                image = CreatQRCode.CombinImage(image, bitmap, 80, 30);
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
                image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
                context.Response.ClearContent();
                context.Response.ContentType = "image/png";
                context.Response.BinaryWrite(memoryStream.ToArray());
                memoryStream.Dispose();
                image.Dispose();
            }
            else if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3))
            {
                System.Drawing.Image image3 = null;
                if (!text3.ToLower().StartsWith("http") && System.IO.File.Exists(context.Server.MapPath(text3)))
                {
                    image3 = System.Drawing.Image.FromFile(context.Server.MapPath(text3));
                }
                else if (text3.ToLower().StartsWith("http"))
                {
                    image3 = this.getNetImg(text3);
                }
                else
                {
                    context.Response.End();
                }
                System.Drawing.Image image4 = null;
                if (!text2.ToLower().StartsWith("http") && System.IO.File.Exists(context.Server.MapPath(text2)))
                {
                    image4 = System.Drawing.Image.FromFile(context.Server.MapPath(text2));
                }
                else if (text2.ToLower().StartsWith("http"))
                {
                    image4 = this.getNetImg(Globals.UrlDecode(text2));
                }
                else
                {
                    context.Response.End();
                }
                System.Drawing.Bitmap bitmap2 = null;
                if (image3 != null)
                {
                    bitmap2 = new System.Drawing.Bitmap(200, 200);
                    System.Drawing.Drawing2D.GraphicsPath clip2 = CreatQRCode.CreateRoundedRectanglePath(new System.Drawing.Rectangle(0, 0, 200, 200), 20);
                    using (System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap2))
                    {
                        graphics2.SetClip(clip2);
                        graphics2.Clear(System.Drawing.Color.White);
                        clip2 = CreatQRCode.CreateRoundedRectanglePath(new System.Drawing.Rectangle(14, 14, 172, 172), 14);
                        graphics2.SetClip(clip2);
                        graphics2.DrawImage(image3, 0, 0, 200, 200);
                    }
                    image3.Dispose();
                }
                image4 = CreatQRCode.CombinImage(image4, bitmap2, 80, 0);
                System.IO.MemoryStream memoryStream2 = new System.IO.MemoryStream();
                image4.Save(memoryStream2, System.Drawing.Imaging.ImageFormat.Png);
                context.Response.ClearContent();
                context.Response.ContentType = "image/png";
                context.Response.BinaryWrite(memoryStream2.ToArray());
                memoryStream2.Dispose();
                image4.Dispose();
            }
            context.Response.Flush();
            context.Response.End();
        }
Ejemplo n.º 52
0
 public void setClip(float x, float y, float width, float height)
 {
     dg.SetClip(new System.Drawing.RectangleF(x, y, width, height));
 }
Ejemplo n.º 53
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="PrintHead">是否打印页眉</param>
        /// <param name="PrintTail">是否打印页脚</param>
        public virtual void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = myPages.LeftMargin;
                TopMargin    = myPages.TopMargin;
                RightMargin  = myPages.RightMargin;
                BottomMargin = myPages.BottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);

            g.PageUnit = myDocument.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.bolDrawHead)
            {
                if (myPages.HeadHeight > 0)
                {
                    g.ResetTransform();
                    g.ResetClip();

                    ClipRect = new System.Drawing.Rectangle(0, 0, myPage.Width, myPages.HeadHeight);
                    g.TranslateTransform(LeftMargin, TopMargin);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawHead(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs(g, ClipRect);
                    //myDocument.RefreshView(e);
                }
                g.ResetClip();
                g.ResetTransform();
            }

            ClipRect = new System.Drawing.Rectangle(
                0,
                myPages.Top,
                myPage.Width,
                myPages.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.TranslateTransform(
                    LeftMargin,
                    TopMargin - myPage.Top + myPages.HeadHeight);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                //rect.Offset(-4, -100);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

//				System.Drawing.RectangleF rect2 = g.ClipBounds ;
//				if( rect.Top < rect2.Top )
//				{
//					float dy = rect2.Top - rect.Top ;
//					rect.Y = rect.Y - dy * 2 ;
//					rect.Height = rect.Height + dy * 4 ;
//				}
//				g.SetClip( rect );

                myDocument.DrawDocument(g, ClipRect);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.bolDrawFooter)
            {
                if (myPages.FooterHeight > 0)
                {
                    g.ResetClip();
                    g.ResetTransform();

                    ClipRect = new System.Drawing.Rectangle(
                        0,
                        myPages.DocumentHeight - myPages.FooterHeight,
                        myPage.Width,
                        myPages.FooterHeight);

                    int dy = 0;
                    if (UseMargin)
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight;
                    }
                    else
                    {
                        dy = myPages.PaperHeight - myPages.BottomMargin - myPages.DocumentHeight - myPages.TopMargin;
                    }
                    g.TranslateTransform(
                        LeftMargin,
                        dy);

                    g.SetClip(new System.Drawing.Rectangle(
                                  ClipRect.Left,
                                  ClipRect.Top,
                                  ClipRect.Width + 1,
                                  ClipRect.Height + 1));

                    myDocument.DrawFooter(g, ClipRect);
                    //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                    //myDocument.RefreshView( e );
                }
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
Ejemplo n.º 54
0
 public override System.Drawing.Bitmap GetNext()
 {
     System.Drawing.Bitmap result;
     lock (this.newBitmap)
     {
         lock (this.oldBitmap)
         {
             if (this.nowState == MarqueeDisplayState.First)
             {
                 this.nowPositionF -= this.step;
                 if (this.nowPositionF < 0f)
                 {
                     this.nowState = MarqueeDisplayState.Stay;
                 }
                 this.nowPosition = (int)this.nowPositionF;
                 this.getPoint1(this.nowPosition);
                 this.getPoint2(this.nowPosition);
                 this.getPoint3(this.nowPosition);
                 this.getPoint4(this.nowPosition);
             }
             else
             {
                 if (this.nowState == MarqueeDisplayState.Stay)
                 {
                     this.StayNum += 42;
                     if (this.StayNum > this.effect.Stay)
                     {
                         if (this.effect.ExitMode == 0)
                         {
                             result = null;
                             return(result);
                         }
                         this.nowState = MarqueeDisplayState.Exit;
                     }
                     result = new System.Drawing.Bitmap(this.newBitmap);
                     return(result);
                 }
                 if (this.nowState == MarqueeDisplayState.Exit)
                 {
                     result = this.Exit.GetNext();
                     return(result);
                 }
             }
             System.Drawing.Bitmap   bitmap    = new System.Drawing.Bitmap(this.oldBitmap);
             System.Drawing.Graphics graphics  = System.Drawing.Graphics.FromImage(bitmap);
             System.Drawing.Bitmap   image     = new System.Drawing.Bitmap(this.newBitmap);
             System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(image);
             System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
             graphicsPath.AddPolygon(this.pa1);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa2);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa3);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphicsPath.ClearMarkers();
             graphicsPath.AddPolygon(this.pa4);
             graphics2.SetClip(graphicsPath);
             graphics2.Clear(System.Drawing.Color.Transparent);
             graphics.DrawImage(image, new System.Drawing.Point(0, 0));
             result = bitmap;
         }
     }
     return(result);
 }
Ejemplo n.º 55
0
        public bool CreadCard(out string imgUrl)
        {
            bool flag = false;
            bool result;

            if (this.resultObj == null || this.resultObj["BgImg"] == null)
            {
                imgUrl = "掌柜名片模板未设置,无法生成名片!";
                result = flag;
            }
            else
            {
                imgUrl = "生成失败";
                System.Drawing.Bitmap bitmap = null;
                if (this.CodeUrl.Contains("weixin.qq.com"))
                {
                    bitmap = this.getNetImg(this.CodeUrl);
                }
                else
                {
                    bitmap = new QRCodeEncoder
                    {
                        QRCodeEncodeMode   = QRCodeEncoder.ENCODE_MODE.BYTE,
                        QRCodeScale        = 8,
                        QRCodeVersion      = 8,
                        QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M
                    }.Encode(this.CodeUrl);
                }
                int num = int.Parse(this.resultObj["DefaultHead"].ToString());
                if (string.IsNullOrEmpty(this.UserHead) || (!this.UserHead.ToLower().StartsWith("http") && !System.IO.File.Exists(Globals.MapPath(this.UserHead))))
                {
                    this.UserHead = "/Utility/pics/imgnopic.jpg";
                }
                if (!this.StoreLogo.ToLower().StartsWith("http") && !System.IO.File.Exists(Globals.MapPath(this.StoreLogo)))
                {
                    this.StoreLogo = "/Utility/pics/headLogo.jpg";
                }
                if (num == 2)
                {
                    this.UserHead = "";
                }
                else if (num == 1)
                {
                    this.UserHead = this.StoreLogo;
                }
                System.Drawing.Image image;
                if (this.UserHead.ToLower().StartsWith("http"))
                {
                    image = this.getNetImg(this.UserHead);
                }
                else if (System.IO.File.Exists(Globals.MapPath(this.UserHead)))
                {
                    image = System.Drawing.Image.FromFile(Globals.MapPath(this.UserHead));
                }
                else
                {
                    image = new System.Drawing.Bitmap(100, 100);
                }
                System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
                graphicsPath.AddEllipse(new System.Drawing.Rectangle(0, 0, image.Width, image.Width));
                System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(image.Width, image.Width);
                using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap2))
                {
                    graphics.SetClip(graphicsPath);
                    graphics.DrawImage(image, 0, 0, image.Width, image.Width);
                }
                image.Dispose();
                bitmap = StoreCardCreater.CombinImage(bitmap, bitmap2, 80);
                System.Drawing.Bitmap   bitmap3   = new System.Drawing.Bitmap(480, 735);
                System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap3);
                graphics2.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics2.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.High;
                graphics2.Clear(System.Drawing.Color.White);
                System.Drawing.Bitmap bitmap4 = new System.Drawing.Bitmap(100, 100);
                if (this.resultObj["BgImg"] != null && System.IO.File.Exists(Globals.MapPath(this.resultObj["BgImg"].ToString())))
                {
                    bitmap4 = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(Globals.MapPath(this.resultObj["BgImg"].ToString()));
                    bitmap4 = StoreCardCreater.GetThumbnail(bitmap4, 735, 480);
                }
                graphics2.DrawImage(bitmap4, 0, 0, 480, 735);
                System.Drawing.Font font  = new System.Drawing.Font("微软雅黑", (float)((int)this.resultObj["myusernameSize"] * 6 / 5));
                System.Drawing.Font font2 = new System.Drawing.Font("微软雅黑", (float)((int)this.resultObj["shopnameSize"] * 6 / 5));
                graphics2.DrawImage(bitmap2, (int)((decimal)this.resultObj["posList"][0]["left"] * 480m), (int)this.resultObj["posList"][0]["top"] * 735 / 490, (int)((decimal)this.resultObj["posList"][0]["width"] * 480m), (int)((decimal)this.resultObj["posList"][0]["width"] * 480m));
                System.Drawing.StringFormat format = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.DisplayFormatControl);
                string   text  = this.resultObj["myusername"].ToString().Replace("{{昵称}}", "$");
                string   text2 = this.resultObj["shopname"].ToString().Replace("{{店铺名称}}", "$");
                string[] array = text.Split(new char[]
                {
                    '$'
                });
                string[] array2 = text2.Split(new char[]
                {
                    '$'
                });
                graphics2.DrawString(array[0], font, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["myusernameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][1]["left"] * 480m)), (float)((int)this.resultObj["posList"][1]["top"] * 735 / 490), format);
                if (array.Length > 1)
                {
                    System.Drawing.SizeF sizeF  = graphics2.MeasureString(" ", font);
                    System.Drawing.SizeF sizeF2 = graphics2.MeasureString(array[0], font);
                    graphics2.DrawString(this.UserName, font, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["nickNameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][1]["left"] * 480m)) + sizeF2.Width - sizeF.Width, (float)((int)this.resultObj["posList"][1]["top"] * 735 / 490), format);
                    System.Drawing.SizeF sizeF3 = graphics2.MeasureString(this.UserName, font);
                    graphics2.DrawString(array[1], font, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["myusernameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][1]["left"] * 480m)) + sizeF2.Width - sizeF.Width * 2f + sizeF3.Width, (float)((int)this.resultObj["posList"][1]["top"] * 735 / 490), format);
                }
                graphics2.DrawString(array2[0], font2, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["shopnameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][2]["left"] * 480m)), (float)((int)this.resultObj["posList"][2]["top"] * 735 / 490));
                if (array2.Length > 1)
                {
                    System.Drawing.SizeF sizeF4 = graphics2.MeasureString(" ", font2);
                    System.Drawing.SizeF sizeF5 = graphics2.MeasureString(array2[0], font2);
                    graphics2.DrawString(this.StoreName, font2, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["storeNameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][2]["left"] * 480m)) + sizeF5.Width - sizeF4.Width, (float)((int)this.resultObj["posList"][2]["top"] * 735 / 490), format);
                    System.Drawing.SizeF sizeF6 = graphics2.MeasureString(this.StoreName, font2);
                    graphics2.DrawString(array2[1], font2, new System.Drawing.SolidBrush(System.Drawing.ColorTranslator.FromHtml(this.resultObj["shopnameColor"].ToString())), (float)((int)((decimal)this.resultObj["posList"][2]["left"] * 480m)) + sizeF5.Width - sizeF4.Width * 2f + sizeF6.Width, (float)((int)this.resultObj["posList"][2]["top"] * 735 / 490), format);
                }
                graphics2.DrawImage(bitmap, (int)((decimal)this.resultObj["posList"][3]["left"] * 480m), (int)this.resultObj["posList"][3]["top"] * 735 / 490, (int)((decimal)this.resultObj["posList"][3]["width"] * 480m), (int)((decimal)this.resultObj["posList"][3]["width"] * 480m));
                bitmap.Dispose();
                if (this.ReferralId == 0)
                {
                    bitmap3.Save(Globals.MapPath(string.Concat(new object[]
                    {
                        Globals.GetStoragePath(),
                        "/DistributorCards/MemberCard",
                        this.userId,
                        ".jpg"
                    })), System.Drawing.Imaging.ImageFormat.Jpeg);
                    imgUrl = string.Concat(new object[]
                    {
                        Globals.GetStoragePath(),
                        "/DistributorCards/MemberCard",
                        this.userId,
                        ".jpg"
                    });
                }
                else
                {
                    bitmap3.Save(Globals.MapPath(string.Concat(new object[]
                    {
                        Globals.GetStoragePath(),
                        "/DistributorCards/StoreCard",
                        this.ReferralId,
                        ".jpg"
                    })), System.Drawing.Imaging.ImageFormat.Jpeg);
                    imgUrl = string.Concat(new object[]
                    {
                        Globals.GetStoragePath(),
                        "/DistributorCards/StoreCard",
                        this.ReferralId,
                        ".jpg"
                    });
                }
                bitmap3.Dispose();
                flag   = true;
                result = flag;
            }
            return(result);
        }