public Image Mark( Image image, string waterMarkText )
        {
            WatermarkText = waterMarkText;

            Bitmap originalBmp = (Bitmap)image;

            // avoid "A Graphics object cannot be created from an image that has an indexed pixel format." exception
            Bitmap tempBitmap = new Bitmap(originalBmp.Width, originalBmp.Height);
            // From this bitmap, the graphics can be obtained, because it has the right PixelFormat
            Graphics g = Graphics.FromImage(tempBitmap);

            using (Graphics graphics = Graphics.FromImage(tempBitmap))
            {
                // Draw the original bitmap onto the graphics of the new bitmap
                g.DrawImage(originalBmp, 0, 0);
                var size =
                    graphics.MeasureString(WatermarkText, Font);
                var brush =
                    new SolidBrush(Color.FromArgb(255, Color));
                graphics.DrawString
                    (WatermarkText, Font, brush,
                    GetTextPosition(image, size));
            }

            return tempBitmap as Image;
        }
示例#2
2
        void PaintVoxel(Graphics graphics, int i, int j)
        {
            Brush brushVoxel_True = new SolidBrush(Color.FromArgb(181, 230, 29));
            Brush brushVoxel_False = new SolidBrush(Color.FromArgb(240, 240, 240));

            graphics.FillRectangle(VoxelsData[i, j] ? brushVoxel_True : brushVoxel_False, VoxelSize * i + 1, VoxelSize * j + 1, VoxelSize - 1, VoxelSize - 1);
        }
示例#3
1
        public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners)
        {
            if (appointment == null)
                throw new ArgumentNullException("appointment");

            if (g == null)
                throw new ArgumentNullException("g");

            if (rect.Width != 0 && rect.Height != 0)
                using (StringFormat format = new StringFormat())
                {
                    format.Alignment = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    if ((appointment.Locked) && isSelected)
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }
                    else
                    {
                        // Draw back
                        using (SolidBrush m_Brush = new SolidBrush(appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }

                    if (isSelected)
                    {
                        using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                            g.DrawRectangle(m_Pen, rect);

                        Rectangle m_BorderRectangle = rect;

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper
                        gripRect.Width += 1;

                        using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
                            g.FillRectangle(m_Brush, gripRect);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, rect);
                    }

                    rect.X += gripRect.Width;
                    g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
                }
        }
示例#4
1
        void DrawGraphics(Object sender, PaintEventArgs PaintNow)
        {
            Rectangle Dot = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight); // Create rectangle (start position, and size X & Y)
            SolidBrush WhiteBrush = new SolidBrush(Color.White); // Create Brush(Color) to paint rectangle

            PaintNow.Graphics.FillRectangle(WhiteBrush, Dot);
        }
示例#5
1
 public override void DoPaint(Graphics g)
 {
     using (Brush b = new SolidBrush(ZenParams.WindowColor))
     {
         g.FillRectangle(b, 0, 0, Width, Height);
     }
 }
示例#6
0
    private void CreateImage(string checkCode)
    {
        int iwidth = (int)(checkCode.Length * 25);

        System.Drawing.Bitmap   image = new System.Drawing.Bitmap(iwidth, 30);
        System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
        System.Drawing.Font     f     = new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold);
        System.Drawing.Brush    b     = new System.Drawing.SolidBrush(System.Drawing.Color.White);
        //g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
        g.Clear(System.Drawing.Color.Blue);
        g.DrawString(checkCode, f, b, 3, 3);

        System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black, 0);
        Random             rand     = new Random();

        for (int i = 0; i < 5; i++)
        {
            int y = rand.Next(image.Height);
            g.DrawLine(blackPen, 0, y, image.Width, y);
        }

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
示例#7
0
        protected void DrawCheckBackground3DLite(PaintEventArgs e, Rectangle bounds, Color checkColor, Color checkBackground, ColorData colors, bool disabledColors) {
            Graphics g = e.Graphics;            
            
            Color field = checkBackground;
            if (!Control.Enabled && disabledColors) {
                field = SystemColors.Control;
            }

            using (Brush fieldBrush = new SolidBrush(field)) {
                using (Pen dark = new Pen(colors.buttonShadow),
                       light = new Pen(colors.buttonFace),
                       lightlight = new Pen(colors.highlight)) {

                    bounds.Width--;
                    bounds.Height--;
                    // fall a little short of SW, NW, NE, SE because corners come out nasty
                    g.DrawPie(dark, bounds, (float)(135 + 1), (float)(90 - 2));
                    g.DrawPie(dark, bounds, (float)(225 + 1), (float)(90 - 2));
                    g.DrawPie(lightlight, bounds, (float)(315 + 1), (float)(90 - 2));
                    g.DrawPie(lightlight, bounds, (float)(45 + 1), (float)(90 - 2));
                    bounds.Inflate(-1, -1);
                    g.FillEllipse(fieldBrush, bounds);
                    g.DrawEllipse(light, bounds);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Draw a preview of the <see cref="ColorPair"/>
        /// </summary>
        /// <param name="e">The paint event args providing the <see cref="Graphics"/> and bounding
        /// rectangle</param>
        public override void PaintValue(PaintValueEventArgs e)
        {
            ColorPair colorPair = (ColorPair)e.Value ;

            using ( SolidBrush b = new SolidBrush(colorPair.Background)) {
                e.Graphics.FillRectangle(b, e.Bounds);
            }

            // Draw the text "ab" using the Foreground/Background values from the ColorPair
            using(SolidBrush b = new SolidBrush(colorPair.Foreground)) {
                using(Font f = new Font("Arial",6)) {
                    RectangleF temp = new RectangleF(e.Bounds.Left,e.Bounds.Top,e.Bounds.Height,e.Bounds.Width) ;
                    temp.Inflate(-2,-2) ;

                    // Set up how we want the text drawn
                    StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap) ;
                    format.Trimming = StringTrimming.EllipsisCharacter ;
                    format.Alignment = StringAlignment.Center ;
                    format.LineAlignment = StringAlignment.Center ;

                    // save the Smoothing mode of the Graphics object so we can restore it
                    SmoothingMode saveMode = e.Graphics.SmoothingMode ;
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias ;
                    e.Graphics.DrawString("ab",f,b,temp,format) ;
                    e.Graphics.SmoothingMode = saveMode ;
                }
            }
        }
示例#9
0
		void DoPaint()
		{
			if (bmp != null)
			{
				using (Graphics g = CreateGraphics())
				{
					g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
					g.InterpolationMode = InterpolationMode.NearestNeighbor;
					g.CompositingMode = CompositingMode.SourceCopy;
					g.CompositingQuality = CompositingQuality.HighSpeed;
					if (ScaleImage)
					{
						g.InterpolationMode = InterpolationMode.NearestNeighbor;
						g.PixelOffsetMode = PixelOffsetMode.Half;
						g.DrawImage(bmp, 0, 0, Width, Height);
					}
					else
					{
						using (var sb = new SolidBrush(Color.Black))
						{
							g.FillRectangle(sb, bmp.Width, 0, Width - bmp.Width, Height);
							g.FillRectangle(sb, 0, bmp.Height, bmp.Width, Height - bmp.Height);
						}
						g.DrawImageUnscaled(bmp, 0, 0);
					}
				}
			}

			CleanupDisposeQueue();
		}
        private void dataSelectionList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            Color color;
            switch (e.ColumnIndex)
            {
                case 2:
                    color = Color.FromArgb(int.Parse(e.SubItem.Text));

                    Rectangle rect = e.Bounds;
                    rect.Inflate(-4, -2);

                    using (SolidBrush brush = new SolidBrush(color))
                    {
                        e.Graphics.FillRectangle(brush, rect);
                        e.Graphics.DrawRectangle(Pens.Black, rect);
                    }
                    break;
                case 3:
                    float x1 = e.SubItem.Bounds.X;
                    float x2 = e.SubItem.Bounds.X + e.SubItem.Bounds.Width;
                    float y = e.SubItem.Bounds.Y + e.SubItem.Bounds.Height / 2;

                    color = Color.FromArgb(int.Parse(e.Item.SubItems[2].Text));
                    float thickness = float.Parse(e.Item.SubItems[1].Text);

                    using (Pen pen = new Pen(color, thickness))
                    {
                        e.Graphics.DrawLine(pen, x1, y, x2, y);
                    }
                    break;
                default:
                    e.DrawDefault = true;
                    break;
            }
        }
示例#11
0
        /// <summary> The Main "Loop" of our program </summary>
        /// <remarks>Since this is Event based, the Form Window is only
        /// updated when something happens: like a mouse being moved.
        /// Otherwise, no resources are being used</remarks>
        void RenderStuff(Object sender, PaintEventArgs PaintNow)
        {
            Rectangle Dot = new Rectangle(SpriteX, SpriteY, 2, 2); // Create rectangle (start position, and size X & Y)
            SolidBrush WhiteBrush = new SolidBrush(Color.White); // Create Brush(Color) to paint rectangle

            PaintNow.Graphics.FillRectangle(WhiteBrush, Dot); // Play Parcheesi!
        }
示例#12
0
        private void pnl_painter_MouseMove(object sender, MouseEventArgs e)
        {
            Brush brush1 = new SolidBrush(Color.Black);
            if (rdo_black.Checked) color = "black";
            else if (rdo_blue.Checked) color = "blue";
            else if (rdo_red.Checked) color = "red";
            switch (color)
            {
                case "black": brush1 = new SolidBrush(Color.Black); break;
                case "blue": brush1 = new SolidBrush(Color.Blue); break;
                case "red": brush1 = new SolidBrush(Color.Red); break;
            }
            if (rdo_small.Checked) size = 4;
            else if (rdo_middle.Checked) size = 8;
            else if (rdo_large.Checked) size = 12;

            x2 = e.X;
            y2 = e.Y;

            Pen pen1 = new Pen(brush1, size);
            pen1.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Flat);
            //pen1.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
            if (shouldPaint)
            {
                Graphics graphics = pnl_painter.CreateGraphics();
                //graphics.FillEllipse(brush1, e.X, e.Y, size, size);
                graphics.DrawLine(pen1, x1, y1, x2, y2);
                graphics.Dispose();
            }

            x1 = e.X;
            y1 = e.Y;
        }
        protected override void OnPaint(PaintEventArgs pea)
        {
            base.OnPaint(pea);

            Graphics grfx = pea.Graphics;

            LinearGradientBrush lgbrush = null;
            Font font = new Font(this.Font.FontFamily, this.Font.Size, this.Font.Style);
            SolidBrush brush = new SolidBrush(this.ForeColor);

            int cw = (this.Width - 20)/7;
            int ch = this.Height - 20;

            for(int i = 0 ; i < 7; i++)
            {
                Rectangle temp = new Rectangle(10+(i*cw), 10, cw, ch );

                if(i < 6)
                    lgbrush = new LinearGradientBrush(temp, colors[i], colors[i+1], LinearGradientMode.Horizontal);
                else
                    lgbrush = new LinearGradientBrush(temp, colors[i], colors[0], LinearGradientMode.Horizontal);

                lgbrush.WrapMode = WrapMode.Tile;
                grfx.FillRectangle(lgbrush, 10+(i*cw), 10, cw, ch );
            }

            grfx.DrawString(this.Text, font, brush, this.Width/3, this.Height/2);
        }
示例#14
0
        protected override void OnDrawItem(DrawItemEventArgs ea)
        {
            ea.DrawBackground();
            ea.DrawFocusRectangle();

            if (ea.Index == -1)
                return;

            Rectangle bounds = ea.Bounds;
            var foreBrush = new SolidBrush(ea.ForeColor);
            int textLeftBound = (IconList == null) ? bounds.Left : bounds.Left + IconList.ImageSize.Width;

            var drawObject = Items[ea.Index];
            if (drawObject is ImageComboBoxItem) {
                var drawItem = (ImageComboBoxItem)drawObject;

                if (drawItem.ImageListIndex != -1 && IconList != null) {
                    //ea.Graphics.FillRectangle(Brushes.Gray, bounds.Left, bounds.Top, IconList.ImageSize.Width, IconList.ImageSize.Height);
                    ea.Graphics.DrawImage(IconList.Images[drawItem.ImageListIndex], bounds.Left, bounds.Top);
                }

                ea.Graphics.DrawString(drawItem.Text, ea.Font, foreBrush, textLeftBound, bounds.Top);
            }
            else {
                ea.Graphics.DrawString(drawObject.ToString(), ea.Font, foreBrush, textLeftBound, bounds.Top);
            }

            base.OnDrawItem(ea);
        }
示例#15
0
        public AccountGridButton()
        {
            InitializeComponent();

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            fontLarge = FONT_LARGE;
            fontSmall = FONT_SMALL;

            brush = new SolidBrush(Color.LightGray);
            pen = new Pen(brush);

            _AccountName = "Example";
            _DisplayName = "*****@*****.**";
            _LastUsed = DateTime.MinValue;
            _ShowAccount = true;

            using (var g = this.CreateGraphics())
            {
                ResizeLabels(g);
            }

            this.Disposed += AccountGridButton_Disposed;
        }
 public override void OnRendererTabPageArea(Graphics gfx, Rectangle tabPageAreaRct)
 {
     Rectangle linesRct = tabPageAreaRct;
     // Draw top 2px line.
     using (Brush brush = new SolidBrush(settings.TabItemSecondColor))
         gfx.FillRectangle(brush, linesRct.Left, linesRct.Top, linesRct.Width, 2);
 }
        /// <summary>
        /// Raises the <see cref="Control.Paint"/> event.
        /// </summary>
        /// <param name="e">A <see cref="PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint( PaintEventArgs e )
        {
            Rectangle clientRect = this.ClientRectangle;

              using( Brush brush = new SolidBrush( this.BackColor ) )
              {
            e.Graphics.FillRectangle( brush, clientRect );
              }

              if( !m_backgroundPaintedOnce )
              {
            m_backgroundPaintedOnce = true;
            this.Invalidate();
            return;
              }

              this.UpdateLayout();

              PreviewPageInfo previewPage = this.CurrentPreviewPage;

              if( previewPage != null )
              {
            Debug.Assert( !m_pageRectangle.IsEmpty, "The page rectangle should not be empty when there is a CurrentPreviewPage. It should have been calculated in UpdateLayout()." );

            Rectangle shadowRectangle = m_pageRectangle;
            shadowRectangle.Offset( ShadowThickness, ShadowThickness );

            Rectangle borderRectangle = m_pageRectangle;
            borderRectangle.Width -= 1; // Need to remove 1 pixel from the width and height for DrawRectangle to work
            borderRectangle.Height -= 1;

            // Draw the shadow
            e.Graphics.FillRectangle( Brushes.Black, shadowRectangle );

            // Draw the page
            e.Graphics.FillRectangle( Brushes.White, m_pageRectangle );

            //TODO: Ne pas dessiner si rectangle plus petit que 2x2
            // Draw the page contents
            e.Graphics.DrawImage( previewPage.Image, m_pageRectangle );

            // Draw the page border
            e.Graphics.DrawRectangle( Pens.Black, borderRectangle );
              }
              else
              {
            using( Brush brush = new SolidBrush( this.ForeColor ) )
            {
              using( StringFormat stringFormat = new StringFormat() )
              {
            stringFormat.Alignment = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString( "No Report", this.Font, brush, clientRect, stringFormat );
              }
            }
              }

              base.OnPaint( e );
        }
示例#18
0
        public void UpdateImage()
        {
            if (!showCheckBox.Checked)
                return;

            Graphics g = pictureBox.CreateGraphics();
            int x;
            int y;
            Pen activeColumnPen = new Pen(new SolidBrush(Color.Gray));
            Pen inactiveColumnPen = new Pen(new SolidBrush(Color.White));
            Brush activeColumnBrush = new SolidBrush(Color.Gray);
            Brush inactiveColumnBrush = new SolidBrush(Color.White);
            for (int ix = 0; ix < _inputs.Width; ix++)
            {
                for (int iy = 0; iy < _inputs.Height; iy++)
                {
                    x = (int)(ix * 5);
                    y = (int)(iy * 5);
                    if (_inputs[ix, iy].GetActive(0))
                        g.FillRectangle(activeColumnBrush, x, y, cellWidth, cellHeight);
                    else
                        g.FillRectangle(inactiveColumnBrush, x, y, cellWidth, cellHeight);
                }
            }
        }
示例#19
0
        protected override void OnDrawItem( DrawItemEventArgs e )
        {
            base.OnDrawItem( e );

            if ( e.Index != -1 )
            {
                object item = Items[e.Index];
                e.DrawBackground();
                e.DrawFocusRectangle();

                bool separator = item is SeparatorItem;

                Rectangle bounds = e.Bounds;
                bool drawSeparator = separator && ( e.State & DrawItemState.ComboBoxEdit ) != DrawItemState.ComboBoxEdit;
                if ( drawSeparator )
                {
                    bounds.Height -= separatorHeight;
                }

                TextRenderer.DrawText( e.Graphics, GetDisplayText( e.Index ), Font, bounds, e.ForeColor, e.BackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter );

                if ( drawSeparator )
                {
                    Rectangle sepRect = new Rectangle( e.Bounds.Left, e.Bounds.Bottom - separatorHeight, e.Bounds.Width, separatorHeight );
                    using ( Brush b = new SolidBrush( BackColor ) )
                    {
                        e.Graphics.FillRectangle( b, sepRect );
                    }
                    e.Graphics.DrawLine( SystemPens.ControlText, sepRect.Left + 2, sepRect.Top + 1, sepRect.Right - 2, sepRect.Top + 1 );
                }
            }
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            var g = pevent.Graphics;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            g.Clear(Parent.BackColor);

            //Hover
            Color c = SkinManager.GetFlatButtonHoverBackgroundColor();
            using (Brush b = new SolidBrush(Color.FromArgb((int)(hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())))
                g.FillRectangle(b, ClientRectangle);

            //Ripple
            if (animationManager.IsAnimating())
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                for (int i = 0; i < animationManager.GetAnimationCount(); i++)
                {
                    var animationValue = animationManager.GetProgress(i);
                    var animationSource = animationManager.GetSource(i);

                    using (Brush rippleBrush = new SolidBrush(Color.FromArgb((int)(101 - (animationValue * 100)), Color.Black)))
                    {
                        var rippleSize = (int)(animationValue * Width * 2);
                        g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize));
                    }
                }
                g.SmoothingMode = SmoothingMode.None;
            }
			g.DrawString(Text.ToUpper(), SkinManager.ROBOTO_MEDIUM_10, Enabled ? (Primary ? SkinManager.ColorScheme.PrimaryBrush : SkinManager.GetPrimaryTextBrush()) : SkinManager.GetFlatButtonDisabledTextBrush(), ClientRectangle, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
        }
        protected override void OnPaint(PaintEventArgs e) {
            Rectangle rect = this.ClientRectangle;
            Graphics g = e.Graphics;
            
            rect.Inflate(-3, -3);

            if (this.Style == ProgressBarStyle.Blocks) {
                if (this.Value > 0) {
                    Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)this.Value / this.Maximum) * rect.Width), rect.Height);

                    var brush = new SolidBrush(Color.FromArgb(255, 48, 53, 64));
                    g.FillRectangle(brush, clip);
                }
            } else {
                int width = (int)Math.Round(this.Width / 2.1f, 0);

                Rectangle clip = new Rectangle((int)Math.Round(mqInt, 0), rect.Y, width, rect.Height);

                if (mqInt >= this.Width + 5f)
                    mqInt  = 0 - width - 5f;

                var brush = new SolidBrush(Color.FromArgb(255, 48, 53, 64));
                g.FillRectangle(brush, clip);
            }
        }
示例#22
0
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            Color       start =  _startColor;
            Color       end = _endColor;

            ToolStrip   toolStrip = e.ToolStrip;
            Graphics    g = e.Graphics;

            int         boundsHeight = e.AffectedBounds.Height;
            int         height = (boundsHeight + _lines - 1) / _lines;
            int         width = e.AffectedBounds.Width;
            int         stripeHeight = height - 1;
            Rectangle   stripeRect;

            using (Brush b = new LinearGradientBrush(new Rectangle(0, 0, width, stripeHeight), start, end, LinearGradientMode.Horizontal))
            {
                for (int idx = 0; idx < _lines; idx++)
                {
                    stripeRect = new Rectangle(0, height * idx + 1, width, stripeHeight);
                    g.FillRectangle(b, stripeRect);
                }
            }

            if (this.DrawEndLine)
            {
                using (Brush solidBrush = new SolidBrush(Color.FromArgb(177, 177, 177)))
                {
                    g.FillRectangle(solidBrush, new Rectangle(0, boundsHeight - 1, width, 1));
                }
            }
        }
示例#23
0
		/// <summary>
		/// Initializes a new instance of the CellRenderer class with default settings
		/// </summary>
		protected CellRenderer() : base()
		{
			this.format = "";

			this.grayTextBrush = new SolidBrush(SystemColors.GrayText);
			this.padding = CellPadding.Empty;
		}
 public static void DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (backgroundImageLayout == ImageLayout.Tile)
     {
         using (TextureBrush brush = new TextureBrush(backgroundImage, WrapMode.Tile))
         {
             if (scrollOffset != Point.Empty)
             {
                 Matrix transform = brush.Transform;
                 transform.Translate((float) scrollOffset.X, (float) scrollOffset.Y);
                 brush.Transform = transform;
             }
             g.FillRectangle(brush, clipRect);
             return;
         }
     }
     Rectangle rect = CalculateBackgroundImageRectangle(bounds, backgroundImage, backgroundImageLayout);
     if ((rightToLeft == RightToLeft.Yes) && (backgroundImageLayout == ImageLayout.None))
     {
         rect.X += clipRect.Width - rect.Width;
     }
     using (SolidBrush brush2 = new SolidBrush(backColor))
     {
         g.FillRectangle(brush2, clipRect);
     }
     if (!clipRect.Contains(rect))
     {
         if ((backgroundImageLayout == ImageLayout.Stretch) || (backgroundImageLayout == ImageLayout.Zoom))
         {
             rect.Intersect(clipRect);
             g.DrawImage(backgroundImage, rect);
         }
         else if (backgroundImageLayout == ImageLayout.None)
         {
             rect.Offset(clipRect.Location);
             Rectangle destRect = rect;
             destRect.Intersect(clipRect);
             Rectangle rectangle3 = new Rectangle(Point.Empty, destRect.Size);
             g.DrawImage(backgroundImage, destRect, rectangle3.X, rectangle3.Y, rectangle3.Width, rectangle3.Height, GraphicsUnit.Pixel);
         }
         else
         {
             Rectangle rectangle4 = rect;
             rectangle4.Intersect(clipRect);
             Rectangle rectangle5 = new Rectangle(new Point(rectangle4.X - rect.X, rectangle4.Y - rect.Y), rectangle4.Size);
             g.DrawImage(backgroundImage, rectangle4, rectangle5.X, rectangle5.Y, rectangle5.Width, rectangle5.Height, GraphicsUnit.Pixel);
         }
     }
     else
     {
         ImageAttributes imageAttr = new ImageAttributes();
         imageAttr.SetWrapMode(WrapMode.TileFlipXY);
         g.DrawImage(backgroundImage, rect, 0, 0, backgroundImage.Width, backgroundImage.Height, GraphicsUnit.Pixel, imageAttr);
         imageAttr.Dispose();
     }
 }
示例#25
0
 public void DrawVertical(Graphics g, LiveSplitState state, float width, Region clipRegion)
 {
     using (var solidBrush = new SolidBrush(LineColor))
     {
         g.FillRectangle(solidBrush, 0.0f, 0.0f, width, VerticalHeight);
     }
 }
示例#26
0
        private void StarField(int stars)
        {
            //creates a counter to track how many stars have been drawn
            int counter = 0;

            //loop to draw all the stars on-screen
            while (counter < stars)
            {
                //creates a randum number generator
                Random randNum = new Random();

                //creates random colour values
                int red = randNum.Next(0, 225);
                int green = randNum.Next(0, 225);
                int blue = randNum.Next(0, 225);

                //creates random size values
                int size = randNum.Next(0, 50);
                int thickness = randNum.Next(0, 40);

                //initialization
                int x = randNum.Next(0, (this.Width));
                int y = randNum.Next(0, (this.Height));
                int z;
                //draw shapes
                Graphics g = this.CreateGraphics();
                SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, red, green, blue));
                g.FillRectangle(blueBrush, x, y, size, size);
                counter++;

                //wait time
                Thread.Sleep(100);
            }
        }
示例#27
0
        public override void Draw(System.Drawing.Graphics gr)
        {
            Brush brush = new SolidBrush(Color.Blue);
            PointF pos = Position;

            gr.FillEllipse(brush, pos.X -radius, pos.Y - radius, 2*radius, 2*radius);
        }
示例#28
0
文件: Form2.cs 项目: Arthyom/C-Xmpls
        private void button1_Click(object sender, EventArgs e)
        {
            // dibujando rectnagulos 
            Graphics papel = pictureBox1.CreateGraphics();
            Pen lapiz = new Pen(Color.Black);

            papel.DrawRectangle(lapiz, 0, 0, 100, 40);

            // dibujar lines 
            papel.DrawLine(lapiz, 20,10, 100,200);

            // dibujar ovalos 
            papel.DrawEllipse(lapiz, 100, 100, 100, 300);


            /// dibujando formas rellenas 
            /// se debe usar una brocha no un lapiz

            Brush brocha = new SolidBrush(Color.Red);

            papel.FillRectangle(brocha, 30, 70, 60, 90);
            papel.FillEllipse(brocha, 80, 30, 20, 50);

            // introducir una imagen puede ser, jpge, gif, bmp etc.
            Bitmap imagenCargada = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg");
            papel.DrawImage(imagenCargada, 50, 50, 200, 200);
        }
示例#29
0
文件: Form2.cs 项目: Arthyom/C-Xmpls
        private void button4_Click(object sender, EventArgs e)
        {
            // mostrar un blanco
            Graphics papel = pictureBox1.CreateGraphics();
            Brush brocha = new SolidBrush(Color.Yellow);

            float xOrigen =30, yOrigen = 30;
      
            // iterar para mostrar la diana 
            for (int i = 0, delta = 100; i < 5; i++ , delta += 50)
            {
                switch (delta)
                {
                    case 300 :
                        Brush b1 = new SolidBrush(Color.White);
                        papel.FillEllipse(b1, xOrigen, yOrigen, xOrigen + delta, yOrigen + delta);
                    break;

                    case 200:
                          Brush b2 = new SolidBrush(Color.Red);
                        papel.FillEllipse(b2, xOrigen, yOrigen, xOrigen + delta, yOrigen + delta);
                    break;

                    case 100:
                          Brush b3 = new SolidBrush(Color.Blue);
                        papel.FillEllipse(b3, xOrigen, yOrigen, xOrigen + delta, yOrigen + delta);
                    break;

                }
                
            }

        }
示例#30
0
 public void ProcessRequest(HttpContext context)
 {
     string TrueName = Utils.GetQueryStringValue("TrueName");
     string CardNo = Utils.GetQueryStringValue("CardNo");
     System.Drawing.Image img = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(VipCardTemplate));
     Graphics g = Graphics.FromImage(img);
     g.DrawImage(img, 0, 0, img.Width, img.Height);
     //设置高质量插值法
     g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
     //设置高质量,低速度呈现平滑程度
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     Font f = new Font("宋体", 17.5f, FontStyle.Bold);
     Brush br = new SolidBrush(Color.FromArgb(100, 80, 80, 80));
     g.DrawString(TrueName, f, br, 52, 200);
     Font f1 = new Font("Arial", 12, FontStyle.Regular);
     Brush br1 = new SolidBrush(Color.FromArgb(100, 102, 102, 102));
     g.DrawString("No:" + CardNo, f1, br1, 25, 225);
     g.Dispose();
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
     byte[] imgbyte = ms.ToArray();
     if (imgbyte != null)
     {
         HttpContext.Current.Response.ClearContent();
         HttpContext.Current.Response.ContentType = "image/Jpeg";
         HttpContext.Current.Response.AddHeader("Content-Length", imgbyte.Length.ToString());
         HttpContext.Current.Response.BinaryWrite(imgbyte);
         HttpContext.Current.Response.Flush();
         HttpContext.Current.Response.End();
     }
 }
示例#31
0
        public override void OnDrawDay(CalendarRendererDayEventArgs e)
        {
            Rectangle r = e.Day.Bounds;

            if (e.Day.Selected)
            {
                using (Brush b = new SolidBrush(ColorTable.DayBackgroundSelected))
                {
                    e.Graphics.FillRectangle(b, r); 
                }
            }
            else if (e.Day.Date.Month % 2 == 0)
            {
                using (Brush b = new SolidBrush(ColorTable.DayBackgroundEven))
                {
                    e.Graphics.FillRectangle(b, r);
                }
            }
            else
            {
                using (Brush b = new SolidBrush(ColorTable.DayBackgroundOdd))
                {
                    e.Graphics.FillRectangle(b, r);
                }
            }

            base.OnDrawDay(e);
        }
示例#32
0
    private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        AppState appState = new AppState();

        appState.Application = _appState.Application;
        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker     mapMaker     = new MapMaker(appState, pixelWidth, pixelHeight, 2);
        MapImageData mapImageData = mapMaker.GetImage();

        System.Drawing.Bitmap bitmap      = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image));
        Transformation        trans       = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent);
        MapGraphics           mapGraphics = MapGraphics.FromImage(bitmap, trans);

        double   minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12;
        Envelope extent  = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY));

        if (extent.Width < minSize)
        {
            extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY));
        }

        if (extent.Height < minSize)
        {
            extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5));
        }

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red));
        System.Drawing.Pen   pen   = new System.Drawing.Pen(System.Drawing.Color.Red, 4);

        mapGraphics.FillEnvelope(brush, extent);
        mapGraphics.DrawEnvelope(pen, extent);

        MemoryStream stream = new MemoryStream();

        bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] mapImage = stream.ToArray();

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
示例#33
0
 /// <summary>
 /// Sets the GraphicBrush property to the given graphics object in the hashtable. If the element doesn't exist, then it adds the graphic element to the hashtable with the given GraphicBrush.
 /// </summary>
 /// <param name="graphic">Graphic element to search or add</param>
 /// <param name="brush">GraphicBrush to set</param>
 public void SetBrush(System.Drawing.Graphics graphic, System.Drawing.SolidBrush brush)
 {
     if (this[graphic] != null)
     {
         ((GraphicsProperties)this[graphic]).GraphicBrush = brush;
     }
     else
     {
         GraphicsProperties tempProps = new GraphicsProperties();
         tempProps.GraphicBrush = brush;
         Add(graphic, tempProps);
     }
 }
示例#34
0
 /// <summary>
 /// Sets the GraphicBrush property to the given graphics object in the hashtable. If the element doesn't exist, then it adds the graphic element to the hashtable with the given GraphicBrush.
 /// </summary>
 /// <param name="graphic">Graphic element to search or add</param>
 /// <param name="color">Color to set</param>
 public void SetPaint(System.Drawing.Graphics graphic, System.Drawing.Color color)
 {
     System.Drawing.Brush brush = new System.Drawing.SolidBrush(color);
     if (this[graphic] != null)
     {
         ((GraphicsProperties)this[graphic]).PaintBrush = brush;
     }
     else
     {
         GraphicsProperties tempProps = new GraphicsProperties();
         tempProps.PaintBrush = brush;
         Add(graphic, tempProps);
     }
 }
示例#35
0
    /// <summary>
    /// 在图片上增加文字水印
    /// </summary>
    /// <param name="Path">原服务器图片路径</param>
    /// <param name="Path_sy">生成的带文字水印的图片路径</param>
    public static void AddWater(string Path, string Path_sy)
    {
        string addText = "51aspx.com";

        System.Drawing.Image    image = System.Drawing.Image.FromFile(Path);
        System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        System.Drawing.Font  f = new System.Drawing.Font("Verdana", 60);
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);

        g.DrawString(addText, f, b, 35, 35);
        g.Dispose();

        image.Save(Path_sy);
        image.Dispose();
    }
示例#36
0
    private void CreateImage(string checkCode)
    {
        int iwidth = (int)(checkCode.Length * 13);

        System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
        Graphics   g  = Graphics.FromImage(image);
        Font       f  = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);
        Brush      b  = new System.Drawing.SolidBrush(Color.LimeGreen);
        HatchBrush hb = new HatchBrush(HatchStyle.SmallConfetti, Color.DarkSeaGreen, Color.White);

        g.FillRectangle(hb, 0, 0, image.Width, image.Height);
        g.DrawString(checkCode, f, b, 3, 3);
        Pen    blackPen = new Pen(Color.Black, 0);
        Random rand     = new Random();

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/gif";
        Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
示例#37
0
        protected override void OnPaint(PaintEventArgs e)
        {
            System.Drawing.Graphics formGraphics;
            formGraphics = this.CreateGraphics();

            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    myBrush = new System.Drawing.SolidBrush(myImage[i, j].getColor());

                    formGraphics.FillRectangle(myBrush, new Rectangle(j * widthStd, i * heightStd, widthStd, heightStd));
                }
            }

            formGraphics.FillRectangle(new System.Drawing.SolidBrush(Color.FromArgb(255, activeR, activeG, activeB)), new Rectangle(14 + 75 + 3, 238, widthStd, heightStd));

            myBrush.Dispose();
            formGraphics.Dispose();
            base.OnPaint(e);
        }
示例#38
0
文件: Paint.cs 项目: HECATE1997/GLP
 private void panelPaint_MouseMove(object sender, MouseEventArgs e)
 {
     if (!hasDrawOrMoveValue)
     {
         mouseX = e.X;
         mouseY = e.Y;
     }
     if (moving && x != -1 && y != -1)
     {
         if (active.Equals("pen"))
         {
             g.DrawLine(pen, new Point(x, y), e.Location);
             x = e.X;
             y = e.Y;
         }
         else if (active.Equals("eraser"))
         {
             //g.DrawRectangle(pen, e.X, e.Y, 24, 24);
             System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
             g.FillRectangle(myBrush, e.X, e.Y, 24, 24);
         }
     }
 }
示例#39
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            System.Drawing.SolidBrush textBrush       = new System.Drawing.SolidBrush(ForeColor);
            System.Drawing.SolidBrush backgroundBrush = new System.Drawing.SolidBrush(backgroundColor);

            //Create graphics object.
            System.Drawing.Graphics formGraphics = this.CreateGraphics();
            formGraphics.FillRectangle(backgroundBrush, new Rectangle(new Point(0, 0), this.Size));

            //String formatting.
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = this.HorizontalAlignment;
            stringFormat.LineAlignment = this.VerticalAlignment;

            //Draw the text.
            formGraphics.DrawString(Text, Font, textBrush, new Rectangle(new Point(Padding.Left, 0), Size), stringFormat);

            //Clean.
            textBrush.Dispose();
            formGraphics.Dispose();
        }
    private void CreateImage(string checkCode)
    {
        int iwidth = (int)(checkCode.Length * 13);

        System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 22);
        Graphics g = Graphics.FromImage(image);
        Font     f = new System.Drawing.Font("Arial", 11, System.Drawing.FontStyle.Bold);
        Brush    b = new System.Drawing.SolidBrush(Color.Red);

        //g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
        g.Clear(Color.White);
        g.DrawString(checkCode, f, b, 3, 3);

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.Cache.SetNoStore();
        Response.ClearContent();
        Response.ContentType = "image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        Response.End();
        g.Dispose();
        image.Dispose();
    }
示例#41
0
 public override System.Drawing.Bitmap GetNext()
 {
     if (this.nowState == MarqueeDisplayState.First)
     {
         this.nowPosition = (int)this.nowPositionF;
         int arg_2C_0 = (this.newBitmap.Width - this.nowPosition) / 2;
         System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(this.newBitmap);
         System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
         System.Drawing.Brush    brush    = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
         this.GetLeft(this.nowPosition);
         graphics.FillPolygon(brush, this.pointLeft);
         graphics.FillPolygon(brush, this.pointRight);
         brush.Dispose();
         graphics.Dispose();
         this.nowPositionF -= this.step;
         if (this.nowPosition <= 0)
         {
             this.nowState = MarqueeDisplayState.Stay;
         }
         return(bitmap);
     }
     return(null);
 }
示例#42
0
 public override System.Drawing.Bitmap GetNext()
 {
     if (this.nowState == MarqueeDisplayState.First)
     {
         int arg_1F_0 = (this.newBitmap.Width - this.nowPosition) / 2;
         System.Drawing.Bitmap   bitmap   = new System.Drawing.Bitmap(this.newBitmap);
         System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
         this.GetLeft(this.nowPosition);
         System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
         int num  = (int)((float)this.newBitmap.Width * this.nowPositionF);
         int num2 = (int)((float)this.newBitmap.Height * this.nowPositionF);
         graphics.FillRectangle(brush, new System.Drawing.Rectangle((this.newBitmap.Width - num) / 2, (this.newBitmap.Height - num2) / 2, num, num2));
         brush.Dispose();
         graphics.Dispose();
         this.nowPositionF += this.step;
         if (this.nowPositionF >= 1f)
         {
             this.nowState = MarqueeDisplayState.Stay;
         }
         return(bitmap);
     }
     return(null);
 }
        static void ga_OnRunComplete(object sender, GaEventArgs e)
        {
            //when the algorithm finishes the best solution is drawn on the form
            var fittest = e.Population.GetTop(1)[0];

            foreach (var gene in fittest.Genes)
            {
                Pen       myPen = new Pen(System.Drawing.Color.Red, 1);
                Rectangle box   = new Rectangle(((Box)gene.ObjectValue).CoordinateX - (rectangleSize / 2), ((Box)gene.ObjectValue).CoordinateY - (rectangleSize / 2), rectangleSize, rectangleSize);
                graphicsObj.DrawRectangle(myPen, box);

                System.Drawing.Font         drawFont   = new System.Drawing.Font("Arial", 16);
                System.Drawing.SolidBrush   drawBrush  = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
                graphicsObj.DrawString(((Box)gene.ObjectValue).Name + "\n" + ((Box)gene.ObjectValue).Weight + "kg", drawFont, drawBrush, ((Box)gene.ObjectValue).CoordinateX - 30, ((Box)gene.ObjectValue).CoordinateY - 26, drawFormat);
            }
            // teh center of mass is an X
            Point centerOfMass = centerOfMassCalculator(fittest);
            Pen   myPenCross   = new Pen(System.Drawing.Color.Red, 2);

            graphicsObj.DrawLine(myPenCross, centerOfMass.X - 5, centerOfMass.Y - 5, centerOfMass.X + 5, centerOfMass.Y + 5);
            graphicsObj.DrawLine(myPenCross, centerOfMass.X + 5, centerOfMass.Y - 5, centerOfMass.X - 5, centerOfMass.Y + 5);
        }
示例#44
0
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method and draw a player health bar
        /// </summary>
        /// <param name="o">The object to draw</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        private void HealthBarDrawer(Object o, PaintEventArgs e)
        {
            Tank t = o as Tank;

            // Draw the bar in a different color based on the player's remaining health
            using (System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(Color.Black)) {
                if (t.hitPoints == 1)
                {
                    brush.Color = Color.Red;
                }
                if (t.hitPoints == 2)
                {
                    brush.Color = Color.Yellow;
                }
                if (t.hitPoints >= 3)
                {
                    brush.Color = Color.Green;
                }

                Rectangle r = new Rectangle(-Constants.HEALTHBARWIDTH / 2, -((Constants.TANKSIZE / 2) + Constants.HEALTHBARHEIGHT * 2), t.hitPoints * (Constants.HEALTHBARWIDTH / 3), Constants.HEALTHBARHEIGHT);
                e.Graphics.FillRectangle(brush, r);
            }
        }
示例#45
0
        //Method to draw the individual game pieces
        // Draws red piece if player 1 and black piece if player 2
        public void drawGamePiece(MouseEventArgs e, Graphics f)
        {
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(pieceColor);
            int xlocal = (e.X / 100);

            if (full[xlocal] >= 0)
            {
                if (player1 && board[xlocal, full[xlocal]] == state.empty)
                {
                    board[xlocal, full[xlocal]] = state.player1;
                    f.FillEllipse(myBrush, xlocal * 100, full[xlocal] * 100, 100, 100);
                    full[xlocal]--;
                    playerTurn();
                }
                else if (player2 && board[xlocal, full[xlocal]] == state.empty)
                {
                    board[xlocal, full[xlocal]] = state.player2;
                    f.FillEllipse(myBrush, xlocal * 100, full[xlocal] * 100, 100, 100);
                    full[xlocal]--;
                    playerTurn();
                }
            }
        }
示例#46
0
        public async Task ShowColors()
        {
            if (Xml.CommandAllowed("show colors", Context))
            {
                List <IRole> colorRoles = Context.Guild.Roles.Where(x => x.Name.StartsWith("Color: ")).OrderBy(x => System.Drawing.Color.FromArgb(x.Color.R, x.Color.R, x.Color.G, x.Color.B).GetHue()).ToList();

                Bitmap bitmap = new Bitmap(320, 15 * colorRoles.Count, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    graphics.Clear(System.Drawing.Color.FromArgb(255, 54, 57, 63));
                    using (System.Drawing.Font fnt = new System.Drawing.Font("Whitney Medium", 10))
                        for (int i = 0; i < colorRoles.Count; i++)
                        {
                            System.Drawing.Color roleColor = System.Drawing.Color.FromArgb(Convert.ToInt32(colorRoles[i].Color.R), Convert.ToInt32(colorRoles[i].Color.G), Convert.ToInt32(colorRoles[i].Color.B));
                            System.Drawing.Brush brush     = new System.Drawing.SolidBrush(roleColor);
                            graphics.DrawString(colorRoles[i].Name, fnt, brush, 5, 15 * i);
                        }
                }

                bitmap.Save("colors.png", System.Drawing.Imaging.ImageFormat.Png);
                await Context.Channel.SendFileAsync("colors.png");
            }
        }
示例#47
0
        private void create()                             ////输出验证码图形并获取验证码汉字
        {
            Encoding gb = Encoding.GetEncoding("gb2312"); //获取GB2312编码页(表)

            object[] bytes = CreateRegionCode(4);         //调用函数产生4个随机中文汉字编码
//根据汉字编码的字节数组解码出中文汉字
            string str1 = gb.GetString((byte[])Convert.ChangeType(bytes[0], typeof(byte[])));
            string str2 = gb.GetString((byte[])Convert.ChangeType(bytes[1], typeof(byte[])));
            string str3 = gb.GetString((byte[])Convert.ChangeType(bytes[2], typeof(byte[])));
            string str4 = gb.GetString((byte[])Convert.ChangeType(bytes[3], typeof(byte[])));
//验证码汉字
               string s = str1 + str2 + str3 + str4;

            chinese_char = s;
//输出验证码图形
            Bitmap     memBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics   g         = Graphics.FromImage(memBitmap);
            SolidBrush brush     = new System.Drawing.SolidBrush(Color.Red);
            Font       drawFont  = new Font("Arial", 18);

            g.DrawString(s, drawFont, brush, 0, 0);
            pictureBox1.Image = memBitmap;             //贴图
        }
        private void DrawShape(int x, int y, int reacSize, Pen pen, int penSize, string reactString, bool solid)
        {
            pbImageBitmap = (Bitmap)(image);
            var       graphics = Graphics.FromImage((Image)pbImageBitmap);
            Rectangle rect     = new Rectangle(x, y, reacSize, reacSize);

            pen.Width = penSize;


            //  pictureBox1.Refresh();
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(pen.Color);
            if (solid)
            {
                graphics.FillRectangle(myBrush, rect);
            }
            else
            {
                graphics.DrawRectangle(pen, rect);
            }
            Font font = new Font("Times New Roman", 12.0f);

            graphics.DrawString(reactString, font, myBrush, x, y);
        }
示例#49
0
        /// <summary>
        /// Draws a box in the right hand side of the screen that will display a players name, score, and hp.
        /// Count determines where on the screeen the box will be drawn. Each box is 50 pixels high, so the
        /// height of each box is 50 times count, where count begins at 0 for the first player

        /// </summary>
        /// <param name="ship">ship that contains the player information</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        /// <param name="count">tracks how many player boxes have been drawn</param>
        private void PlayerDrawer(PaintEventArgs e, Ship ship, int count)
        {
            int height = 50 * count; // determines how far down to draw each player box

            string name = ship.GetName() + ": " + ship.GetScore().ToString();

            using (System.Drawing.SolidBrush whiteBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White))
                using (System.Drawing.SolidBrush greenBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green))
                    using (System.Drawing.SolidBrush blackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black))
                    {
                        e.Graphics.DrawString(name, new Font("Arial", 12), blackBrush, 10, 2 + height);

                        // Rectangles are drawn starting from the top-left corner.
                        // So if we want the rectangle centered on the player's location, we have to offset it
                        // by half its size to the left (-width/2) and up (-height/2)
                        Rectangle r  = new Rectangle(5, (20 + height), 188, 20);
                        Rectangle r2 = new Rectangle(7, (22 + height), 184, 16);
                        Rectangle r3 = new Rectangle(9, (24 + height), 36 * ship.GetHp(), 12);
                        e.Graphics.FillRectangle(blackBrush, r);
                        e.Graphics.FillRectangle(whiteBrush, r2);
                        e.Graphics.FillRectangle(greenBrush, r3);
                    }
        }
示例#50
0
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            int cnt2 = 0;

            while (cnt2 < num && arr[cnt2, 0] + arr[cnt2, 2] < this.pictureBox1.Width)
            {
                System.Drawing.SolidBrush myBrush      = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                System.Drawing.Graphics   formGraphics = this.pictureBox1.CreateGraphics();
                formGraphics.FillRectangle(myBrush, new Rectangle(arr[cnt2, 0], arr[cnt2, 1], arr[cnt2, 2], arr[cnt2, 3]));
                myBrush.Dispose();
                formGraphics.Dispose();
                cnt2++;
            }
            while (cnt2 < num && arr[cnt2, 0] < this.pictureBox1.Width)
            {
                System.Drawing.SolidBrush myBrush      = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                System.Drawing.Graphics   formGraphics = this.pictureBox1.CreateGraphics();
                formGraphics.FillRectangle(myBrush, new Rectangle(arr[cnt2, 0], arr[cnt2, 1], this.pictureBox1.Width - arr[cnt2, 0], arr[cnt2, 3]));
                myBrush.Dispose();
                formGraphics.Dispose();
                cnt2++;
            }
        }
示例#51
0
    /// <summary>
    /// 在图片上添加文字水印
    /// </summary>
    /// <param name="path">要添加水印的图片路径</param>
    /// <param name="syPath">生成的水印图片存放的位置</param>
    public static void AddWaterWord(Stream path, string syPath,float x,float y,string syWord)
    {
       
        System.Drawing.Image image = System.Drawing.Image.FromStream(path);

        //新建一个画板
        System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
        graphic.DrawImage(image, 0, 0, image.Width, image.Height);

        //设置字体
        System.Drawing.Font f = new System.Drawing.Font("PingFang SC", 28);

        //设置字体颜色
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

        graphic.DrawString(syWord, f, b, x, y);
        graphic.Dispose();

        //保存文字水印图片
        image.Save(syPath);
        image.Dispose();

    }
示例#52
0
        public void draw(Graphics G)
        {
            Pen P = new Pen(Color.Black);

            System.Drawing.Font         drawFont   = new System.Drawing.Font("Arial", 16);
            System.Drawing.SolidBrush   drawBrush  = new System.Drawing.SolidBrush(System.Drawing.Color.OrangeRed);
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();

            G.DrawEllipse(P, px, py, 150, 150);                   //Head
            G.DrawEllipse(P, px + 17, py + 40, 50, 25);           //Left eye
            G.DrawEllipse(P, px + 30, py + 40, 25, 25);           //Left eye
            G.DrawEllipse(P, px + 87, py + 40, 50, 25);           //Right eye
            G.DrawEllipse(P, px + 100, py + 40, 25, 25);          //Right eye
            G.DrawEllipse(P, px + 50, py + 100, 50, 25);          //Mouth
            G.DrawEllipse(P, px + 45, py + 95, 60, 35);           //Mouth
            G.DrawLine(P, px + 51, py + 113, px + 100, py + 113); //Tooth
            G.DrawLine(P, px + 60, py + 104, px + 60, py + 123);  //Tooth
            G.DrawLine(P, px + 70, py + 100, px + 70, py + 125);  //Tooth
            G.DrawLine(P, px + 80, py + 100, px + 80, py + 125);  //Tooth
            G.DrawLine(P, px + 90, py + 104, px + 90, py + 123);  //Tooth

            G.DrawString("Dylan", drawFont, drawBrush, px + 135, py + 10, drawFormat);
        }
示例#53
0
    public void Display(Graphics g, Graphics gB)
    {
        if (this.state == 0)
        {
            System.Drawing.SolidBrush cellBrushClear = new System.Drawing.SolidBrush(SystemColors.Control);

            g.FillRectangle(cellBrushClear, (this.x) * CELL_SIZE + (int)GRID_STATE, (this.y) * CELL_SIZE + (int)GRID_STATE,
                            CELL_SIZE - (int)GRID_STATE, CELL_SIZE - (int)GRID_STATE);

            gB.FillRectangle(cellBrushClear, (this.x) * CELL_SIZE + (int)GRID_STATE, (this.y) * CELL_SIZE + (int)GRID_STATE,
                             CELL_SIZE - (int)GRID_STATE, CELL_SIZE - (int)GRID_STATE);
        }
        else
        {
            System.Drawing.SolidBrush cellBrush = new System.Drawing.SolidBrush(Colors.colors[State]);

            g.FillRectangle(cellBrush, (this.x) * CELL_SIZE + (int)GRID_STATE, (this.y) * CELL_SIZE + (int)GRID_STATE,
                            CELL_SIZE - (int)GRID_STATE, CELL_SIZE - (int)GRID_STATE);

            gB.FillRectangle(cellBrush, (this.x) * CELL_SIZE + (int)GRID_STATE, (this.y) * CELL_SIZE + (int)GRID_STATE,
                             CELL_SIZE - (int)GRID_STATE, CELL_SIZE - (int)GRID_STATE);
        }
    }
示例#54
0
        // See http://msdn.microsoft.com/en-us/library/ms404305(v=VS.100).aspx
        // for why we have to draw it manually
        private void OnMainTabControlDrawItem(object sender, DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            Brush    currentTextBrush;

            // Get the item from the collection.
            TabPage currentTabPage = m_mainTabControl.TabPages[e.Index];

            // Get the real bounds for the tab rectangle.
            Rectangle tabBounds = m_mainTabControl.GetTabRect(e.Index);

            if (e.State == DrawItemState.Selected)
            {
                // Draw a different background color, and don't paint a focus rectangle.
                currentTextBrush = SystemBrushes.ActiveCaptionText;
                g.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);
            }
            else
            {
                currentTextBrush = new System.Drawing.SolidBrush(e.ForeColor);
                e.DrawBackground();
            }

            Font currentTabFont = new Font("Tahoma", 11F, FontStyle.Regular, GraphicsUnit.Pixel);

            // Draw string. Center the text.
            StringFormat stringFlags = new StringFormat();

            stringFlags.Alignment     = StringAlignment.Center;
            stringFlags.LineAlignment = StringAlignment.Center;
            g.DrawString(
                currentTabPage.Text,
                currentTabFont,
                currentTextBrush,
                tabBounds,
                new StringFormat(stringFlags));
        }
示例#55
0
        private async void Lane1Play(CancellationToken token)
        {
            words[0] = library.generateWord(); //Generates a word from the Library
            String data = this.filterProcessor(words[0]);

            for (int i = 0; i < 760; i++)
            {
                if (i % 20 == 0)
                {
                    this.updateWords();
                }
                try
                {
                    Lane1Panel.Refresh();
                    Graphics dc = Lane1Panel.CreateGraphics();
                    shape.DrawShape(dc, i, data);
                    token.ThrowIfCancellationRequested();
                    await Task.Delay(delaytime, token); //Delays the task from happening again for a second
                }
                catch (Exception e)
                {
                    words[0] = null;
                    break; //break here because task won't end for a while if you exit the application before finishing
                }
                if (i.Equals(759))
                {
                    Font font = new Font("Arial", 10, FontStyle.Bold);
                    System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
                    this.Lane1Panel.Refresh();
                    Graphics dc = Lane1Panel.CreateGraphics();
                    dc.DrawString("LANE ENDED.", font, myBrush, new Point(340, 30));
                    words[0] = null;
                    this.checkIfLost();
                }
                this.updateWords();
            }
        }
示例#56
0
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method
        /// Draws tank epxlosions using tankTimer
        /// </summary>
        private void ExplosionDrawer(object o, PaintEventArgs e)
        {
            //Gets tank. If world no longer has tank, remove tank from tankTimer and return
            Tank t    = o as Tank;
            Tank temp = new Tank();

            if (!theWorld.GetTank(t.ID, out temp))
            {
                tankTimer.Remove(t);
                return;
            }

            //Gets the tank object and sets width and height for explosion using tankTimer
            int frames = tankTimer[t];
            int radius;

            if (frames <= 50)
            {
                radius = frames * 2;
            }
            else if (frames <= 150)
            {
                radius = 150 - frames;
            }
            else
            {
                radius = 0;
            }

            //Creates rectangle and then draws ellipse/circle of explosion
            using (System.Drawing.SolidBrush redBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White))
            {
                Rectangle r = new Rectangle(-(radius / 2), -(radius / 2), radius, radius);

                e.Graphics.FillEllipse(redBrush, r);
            }
        }
示例#57
0
        public static void SetMotorLine(Form form, PictureBox ctrl, int motor)
        {
            if (ctrl.InvokeRequired)
            {
                SetMotorLineCallback d = new SetMotorLineCallback(SetMotorLine);
                form.Invoke(d, new object[] { form, ctrl, motor });
            }
            else
            {
                if (ctrl.Image == null)
                {
                    Bitmap bmp = new Bitmap(ctrl.Width, ctrl.Height);
                    ctrl.Image = bmp;
                }

                using (Graphics g = Graphics.FromImage(ctrl.Image)) {
                    System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

                    double angle     = Math.PI * motor / 180.0;
                    double sin_angle = Math.Sin(angle);
                    double cos_angle = Math.Cos(angle);

                    int   center_x = 250;
                    int   center_y = 250;
                    int   x        = center_x + Convert.ToInt32(cos_angle * 200);
                    int   y        = center_y + Convert.ToInt32(sin_angle * 200);
                    Point s        = new Point(center_x, center_y);
                    Point f        = new Point(x, y);
                    g.FillRectangle(myBrush, new Rectangle(0, 0, 500, 500));
                    g.DrawLine(new Pen(Color.Green, 2), s, f);

                    myBrush.Dispose();
                }

                ctrl.Invalidate();
            }
        }
        /// <summary>
        ///create img
        /// </summary>
        /// <param name="checkCode"></param>
        private void CreateImage(HttpContext context, string checkCode)
        {
            int iwidth = (int)(checkCode.Length * 12);
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth, 20);
            Graphics g = Graphics.FromImage(image);
            g.Clear(Color.White);
            //color
            Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Chocolate, Color.Brown, Color.DarkCyan, Color.Purple };
            Random rand = new Random();
            //font & colored char
            for (int i = 0; i < checkCode.Length; i++)
            {
                int cindex = rand.Next(7);
                Font f = new System.Drawing.Font("Microsoft Sans Serif", 11);
                Brush b = new System.Drawing.SolidBrush(c[cindex]);
                g.DrawString(checkCode.Substring(i, 1), f, b, (i * 10) + 1, 0, StringFormat.GenericDefault);
            }

            //draw backgound noise
            for (int i = 0; i < 100; i++)
            {
                int x = rand.Next(image.Width);
                int y = rand.Next(image.Height);
                image.SetPixel(x, y, Color.FromArgb(rand.Next()));
            }
            //draw border
            g.DrawRectangle(new Pen(Color.Black, 0), 0, 0, image.Width - 1, image.Height - 1);

            //output to browser
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            context.Response.ClearContent();
            context.Response.ContentType = "image/Jpeg";
            context.Response.BinaryWrite(ms.ToArray());
            g.Dispose();
            image.Dispose();
        }
示例#59
0
        public Form1()
        {
            InitializeComponent();

            pathprog             = System.Environment.CurrentDirectory.ToString();
            pathprog             = pathprog.Substring(0, pathprog.Length - 9);
            pathformbackground1  = pathprog + "formbackground1.bmp";
            this.BackgroundImage = System.Drawing.Image.FromFile(pathformbackground1);
            pathformbackground2  = pathprog + "formbackground2.bmp";
            pathCraneHelp        = pathprog + "CraneHelp.chm";

            dis = 21.84;
            x   = 0;

            ujemnie_srednia_pow  = -6.75;
            zero_pow             = 0;
            dodatnio_srednia_pow = 25;
            dodatnio_duza_pow    = 30;

            formGraphics   = this.CreateGraphics();
            yellowBrush    = new SolidBrush(Color.Orange);
            blackPen       = new Pen(Color.Black);
            blackPen.Width = 1;
            grayPen        = new Pen(Color.LightSkyBlue);
            grayPen.Width  = 1;
            grayBrush      = new SolidBrush(Color.LightSkyBlue);
            blackBrush     = new SolidBrush(Color.Black);

            id       = 0;
            angle    = 0;
            distance = 0;
            system   = "Manual";
            power    = 0;
            pow      = 0;

            zerobutton = 0;
        }
示例#60
0
        private void DoInstructions(Single Xa, Single Xb, Single Ya, Single Yb, Pen p)
        {
            BorderStyleEnum ls = getLineStyle(p);


            switch (p.Brush.GetType().Name)
            {
            case "SolidBrush":
                System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)p.Brush;
                PageLine pl = new PageLine();
                pl.X  = X + Xa * SCALEFACTOR;
                pl.Y  = Y + Ya * SCALEFACTOR;
                pl.X2 = X + Xb * SCALEFACTOR;
                pl.Y2 = Y + Yb * SCALEFACTOR;

                StyleInfo SI = new StyleInfo();
                SI.Color        = theBrush.Color;
                SI.BColorTop    = theBrush.Color;
                SI.BStyleTop    = ls;
                SI.BWidthTop    = p.Width * SCALEFACTOR;
                SI.BColorBottom = theBrush.Color;
                SI.BStyleBottom = ls;
                SI.BWidthBottom = p.Width * SCALEFACTOR;
                SI.BColorLeft   = theBrush.Color;
                SI.BStyleLeft   = ls;
                SI.BWidthLeft   = p.Width * SCALEFACTOR;
                SI.BColorRight  = theBrush.Color;
                SI.BStyleRight  = ls;
                SI.BWidthRight  = p.Width * SCALEFACTOR;
                pl.SI           = SI;
                items.Add(pl);
                break;

            default:
                break;
            }
        }