コード例 #1
2
    private void ResimOlustur(int genislik, int yukseklik)
    {
        Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb);

        Graphics g = Graphics.FromImage(bitmap);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        Rectangle rect = new Rectangle(0, 0, genislik, yukseklik);

        HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White);
        g.FillRectangle(hatchBrush, rect);

        SizeF size;
        float fontSize = rect.Height + 1;
        Font font;

        do
        {
            fontSize--;
            font = new Font(System.Drawing.FontFamily.GenericSerif.Name, fontSize, FontStyle.Bold);
            size = g.MeasureString(this.text, font);
        } while (size.Width > rect.Width);

        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;

        GraphicsPath path = new GraphicsPath();
        path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
        float v = 4F;
        PointF[] points =
   {
    new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
    new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
    new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
    new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
   };
        Matrix matrix = new Matrix();
        matrix.Translate(0F, 0F);
        path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

        hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
        g.FillPath(hatchBrush, path);

        int m = Math.Max(rect.Width, rect.Height);
        for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
        {
            int x = this.random.Next(rect.Width);
            int y = this.random.Next(rect.Height);
            int w = this.random.Next(m / 50);
            int h = this.random.Next(m / 50);
            g.FillEllipse(hatchBrush, x, y, w, h);
        }

        font.Dispose();
        hatchBrush.Dispose();
        g.Dispose();

        this.Image = bitmap;
    }
コード例 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Response.Clear();
     Response.ContentType = "image/bmp";
     string st = "",s="";
     Random rnd = new Random();
     Int32 num=0,ch=0;
     for (int i = 0; i < 5; i++)
     {
         ch=rnd.Next(2);
         if (ch == 0)
             num = rnd.Next(65, 91);
         if (ch == 0)
             num = rnd.Next(97, 122);
         else
             num = rnd.Next(48, 57);
         s += (Convert.ToChar(num)).ToString();
         st += (Convert.ToChar(num)).ToString() + " ";
     }
     Session.Add("captcha", s);
     Bitmap bmp = new Bitmap(210, 80);
     Graphics g = Graphics.FromImage(bmp);
     Pen p = new Pen(Color.Aqua);
     HatchBrush br = new HatchBrush(HatchStyle.DottedGrid, Color.Aqua, Color.LightGray);
     SolidBrush b = new SolidBrush(Color.Goldenrod);
     Font f = new Font("Chillar", 36);
     g.FillRectangle(br, new Rectangle(0, 0, 210, 80));
     g.DrawString(st, f, b, new Point(5, 5));
     bmp.Save(Response.OutputStream, ImageFormat.Bmp);
     g.DrawLine(p, 20, 10, 210, 80);
 }
コード例 #3
0
    void OnPaint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;

        HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.Black, this.BackColor);
        g.FillRectangle(hb, 10, 15, 90, 60);

        hb = new HatchBrush(HatchStyle.Percent05, Color.Black, this.BackColor);
        g.FillRectangle(hb, 130, 15, 90, 60);

        hb = new HatchBrush(HatchStyle.SolidDiamond, Color.Black, this.BackColor);
        g.FillRectangle(hb, 250, 15, 90, 60);

        hb = new HatchBrush(HatchStyle.DiagonalBrick, Color.Black, this.BackColor);
        g.FillRectangle(hb, 10, 105, 90, 60);

        hb = new HatchBrush(HatchStyle.Divot, Color.Black, this.BackColor);
        g.FillRectangle(hb, 130, 105, 90, 60);

        hb = new HatchBrush(HatchStyle.Wave, Color.Black, this.BackColor);
        g.FillRectangle(hb, 250, 105, 90, 60);

        hb = new HatchBrush(HatchStyle.ZigZag, Color.Black, this.BackColor);
        g.FillRectangle(hb, 10, 195, 90, 60);

        hb = new HatchBrush(HatchStyle.Sphere, Color.Black, this.BackColor);
        g.FillRectangle(hb, 130, 195, 90, 60);

        hb = new HatchBrush(HatchStyle.Shingle, Color.Black, this.BackColor);
        g.FillRectangle(hb, 250, 195, 90, 60);

        hb.Dispose();
        g.Dispose();
    }
コード例 #4
0
        protected override void PaintHook()
        {
            HatchBrush hb1 = new HatchBrush(HatchStyle.Trellis, Color.FromArgb(15, 15, 15));
            HatchBrush hb2 = new HatchBrush(HatchStyle.Trellis, Color.FromArgb(35, 35, 35));
            HatchBrush hb3 = new HatchBrush(HatchStyle.Trellis, Color.FromArgb(0, 0, 0));

            //G.Clear(C1);

            G.Clear(BackColor);

            G.FillRectangle(B5, 0, 0, Width, Height);
            //BackGround'
            G.FillRectangle(B5, 0, 0, Width, 15);
            //Outside'
            G.DrawRectangle(P1, 0, 15, Width - 1, Convert.ToInt32(Height - 16));
            //Green'
            G.FillRectangle(hb1, 5, 5, Width - 15, 20);
            //Gloss
            G.FillRectangle(hb1, 5, 5, Width - 15, 10);
            G.DrawRectangle(P1, 5, 5, Width - 15, 20);
            DrawText(B2, HorizontalAlignment.Center, 0, 3);
        }
コード例 #5
0
        public MainForm()
        {
            InitializeComponent();

            FontFamily fontFamily = new FontFamily("Arial");
            Font       font       = new Font(
                fontFamily,
                12,
                FontStyle.Regular,
                GraphicsUnit.Pixel);

            bmp = new Bitmap(panelCanvas.Width, panelCanvas.Height);
            Graphics g = Graphics.FromImage(bmp);

            g.Clear(Color.White);
            gr = panelCanvas.CreateGraphics();

            Pen        pen   = new Pen(panelPenColor.BackColor, 3);
            HatchBrush brush = new HatchBrush(HatchStyle.BackwardDiagonal, panelPenColor.BackColor, panelBrushColor.BackColor);

            dutils            = new DrawingUtils(g, pen, brush, font);
            panelCanvas.Image = bmp;

            startPosition = new Point();
            endPosition   = new Point();
            comboBoxBrushStyle.Items.Add("SolidBrush");
            foreach (string styleName in Enum.GetNames(typeof(HatchStyle)))
            {
                comboBoxBrushStyle.Items.Add(styleName);
            }
            comboBoxBrushStyle.SelectedIndex = 0;

            foreach (string styleName in Enum.GetNames(typeof(DashStyle)))
            {
                comboBoxPenStyles.Items.Add(styleName);
            }
            comboBoxPenStyles.Items.Remove("Custom");
            comboBoxPenStyles.SelectedIndex = 0;
        }
コード例 #6
0
        protected override void PaintHook()
        {
            G.Clear(Color.FromArgb(22, 22, 22));

            ///''''''' Draw Header '''''''

            G.DrawRectangle(new Pen(Color.FromArgb(32, 32, 32)), new Rectangle(1, 1, Width - 3, Height - 3));

            LinearGradientBrush Header = new LinearGradientBrush(new Rectangle(0, 0, Width - 1, 26), Color.FromArgb(25, 25, 25), Color.FromArgb(40, 40, 40), 270);

            G.FillRectangle(Header, new Rectangle(0, 0, Width - 1, 26));

            HatchBrush HeaderHatch = new HatchBrush(HatchStyle.Trellis, Color.FromArgb(35, Color.Black), Color.Transparent);

            G.FillRectangle(HeaderHatch, new Rectangle(0, 0, Width - 1, 26));
            G.FillRectangle(new SolidBrush(Color.FromArgb(13, Color.White)), 0, 0, Width - 1, 13);

            G.DrawLine(new Pen(Color.FromArgb(42, 42, 42)), 0, 13, Width - 1, 13);
            // Cuz it has a bug dont worry i will fix it =)

            G.DrawRectangle(new Pen(Color.FromArgb(6, 6, 6)), new Rectangle(0, 0, Width - 1, Height - 1));
            // Draw Border
            //G.DrawRectangle(New Pen(Color.FromArgb(6, 6, 6)), New Rectangle(0, 0, Width - 1, 27))
            //G.DrawRectangle(New Pen(Color.FromArgb(32, 32, 32)), New Rectangle(0, 0, Width - 1, Height - 1))


            G.DrawRectangle(new Pen(Color.FromArgb(6, 6, 6)), new Rectangle(1, 1, Width - 3, 25));
            G.DrawRectangle(new Pen(Color.FromArgb(32, 32, 32)), new Rectangle(1, 1, Width - 3, 24));

            ///''''''' Draw Text and Shadw '''''''
            //G.DrawString(Text, Font, New SolidBrush(Color.Black), New Point(9, 7)) ' Text Shadow
            //G.DrawString(Text, Font, New SolidBrush(Color.FromArgb(255, 150, 0)), New Point(8, 6))

            DrawText(new SolidBrush(Color.Black), HorizontalAlignment.Center, 1, 1);
            DrawText(new SolidBrush(Color.FromArgb(255, 150, 0)), HorizontalAlignment.Center, 2, 2);

            //DrawCorners(Color.FromArgb(22, 22, 22), 1)
            //DrawCorners(Color.FromArgb(22, 22, 22))
        }
コード例 #7
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {                                                              //элипс и фулл элипс
            e.Graphics.DrawEllipse(new Pen(Color.Red, 2), new Rectangle(50 - d, 50 - d, 50 + 2 * d, 50 + 2 * d));
            e.Graphics.FillEllipse(pen.Brush, new Rectangle(250 - d1, 50 - d1, 50 + 3 * d1, 50 + 3 * d1));

            e.Graphics.FillRectangle(pen1.Brush, 50 + d2, 250, 50 + 3, 50 + 3); //квадрат фулл

            e.Graphics.FillPolygon(pen2.Brush, points4);                        //звезда с помощью двух треугольников
            e.Graphics.FillPolygon(pen2.Brush, points5);

            e.Graphics.DrawPolygon(pen3, points1);  //многоугольник

            //HatchBrush закрашивает фигуру еще и может сделать например ввиде кирпичек и т.д
            HatchBrush hBrush = new HatchBrush(HatchStyle.Divot, color, Color.FromArgb(255, 128, 255, 255));

            e.Graphics.FillEllipse(hBrush, 230 - d, 230 - d, 20 + 2 * d, 20 + 2 * d);



            //////////////////////////////////////////////////
            int    n = 5;             // число вершин
            double R = 25, r = 50;    // радиусы
            double alpha = 0;         // поворот
            double x0 = 500, y0 = 90; // центр                   //

            //ЗВЕЗДА КАК В Paint
            PointF[] points = new PointF[2 * n + 1];             //
            double   a = alpha, da = Math.PI / n, l;

            for (int k = 0; k < 2 * n + 1; k++)
            {
                l         = k % 2 == 0 ? r : R;
                points[k] = new PointF((float)(x0 + l * Math.Cos(a)), (float)(y0 + l * Math.Sin(a)));
                a        += da;
            }

            e.Graphics.DrawLines(Pens.Black, points);
            ////////////////////////////////////////////////
        }
コード例 #8
0
        protected override void PaintHook()
        {
            G.Clear(Color.FromArgb(14, 14, 14));

            LinearGradientBrush LGB1 = new LinearGradientBrush(new Rectangle(0, 0, Width - 1, Height - 1), R1, R2, 90);

            G.FillRectangle(LGB1, new Rectangle(0, 0, Width - 1, Height - 25));

            HatchBrush BodyHatch = new HatchBrush(HatchStyle.NarrowVertical, Color.FromArgb(15, Color.White), Color.Transparent);

            G.FillRectangle(BodyHatch, new Rectangle(0, 0, Width - 1, Height - 1));

            G.DrawRectangle(Border, new Rectangle(0, 0, Width - 1, 25));
            G.DrawRectangle(Border, new Rectangle(0, 0, Width - 1, Height - 1));
            G.DrawString(Text, Font, textcolor, new Point(7, 6));

            G.FillRectangle(new SolidBrush(Color.FromArgb(20, 20, 20)), new Rectangle(1, 26, Width - 2, Height - 27));
            // BG

            G.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(40, 40, 40))), new Rectangle(1, 1, Width - 3, Height + 25));
            G.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(40, 40, 40))), new Rectangle(1, 26, Width - 3, Height - 28));
        }
コード例 #9
0
        /// <summary>
        /// Imagines the paint hook.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        private void ImaginePaintHook(PaintEventArgs e)
        {
            //Bitmap B = new Bitmap(Width, Height);
            Graphics G = e.Graphics;

            G.SmoothingMode = SmoothingMode.HighQuality;
            G.Clear(Parent.BackColor);
            dynamic progressWidth = Convert.ToInt32(Value * (1 / Maximum) * Width);


            HatchBrush HB = new HatchBrush(HatchStyle.BackwardDiagonal, Color.FromArgb(15, Color.LightBlue), Color.Transparent);

            G.FillRectangle(new SolidBrush(Prog), 0, 0, progressWidth, Height);
            G.FillRectangle(HB, new Rectangle(0, 0, progressWidth, Height));

            DrawGradients(G, Color.FromArgb(40, Color.White), Color.FromArgb(10, Color.White), ClientRectangle);
            DrawBorders(G, Pens.Black, ClientRectangle);

            //e.Graphics.DrawImage(B, 0, 0);
            //G.Dispose();
            //B.Dispose();
        }
コード例 #10
0
        protected override void PaintHook()
        {
            G.Clear(BackColor);
            HatchBrush          HB  = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.FromArgb(80, Color.Gray), Color.Transparent);
            LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(1, 1, 16, 16), Color.FromArgb(255, 222, 222, 222), Color.FromArgb(255, 200, 200, 200), 90f);

            G.SmoothingMode = SmoothingMode.AntiAlias;

            G.FillEllipse(LGB, 1, 1, 15, 15);
            G.FillEllipse(HB, 1, 1, 15, 15);
            G.DrawEllipse(new Pen(Color.Black), 0, 0, 16, 16);

            if ((_Checked))
            {
                //G.FillEllipse(LGB, 4, 4, 8, 8)
                //G.FillEllipse(HB, 4, 4, 8, 8)
                G.FillEllipse(new SolidBrush(Color.Black), 4, 4, 8, 8);
                //G.DrawString("a", New Font("Webdings", 13), Brushes.Black, New Point(-2, -2))
            }

            G.DrawString(Text, Font, Brushes.Black, 18, 2);
        }
コード例 #11
0
        void Studio_PaintHook(PaintEventArgs e)
        {
            Studio_B1 = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.FromArgb(20, 40, 70), Color.FromArgb(40, 60, 90));
            Studio_B2 = new SolidBrush(Color.White);

            G.DrawRectangle(Studio_P1, ClientRectangle);

            Studio_Path.Reset();
            Studio_Path.AddLines(new Point[] {
                new Point(2, 0),
                new Point(Width - 3, 0),
                new Point(Width - 1, 2),
                new Point(Width - 1, Height - 3),
                new Point(Width - 3, Height - 1),
                new Point(2, Height - 1),
                new Point(0, Height - 3),
                new Point(0, 2),
                new Point(2, 0)
            });
            G.SetClip(Studio_Path);

            G.Clear(Studio_C1);
            DrawGradient(Studio_C2, Studio_C3, 0, 0, Width, 30);

            Studio_RT1 = new Rectangle(12, 30, Width - 24, Height - 12 - 30);
            G.FillRectangle(Studio_B1, Studio_RT1);

            DrawGradient(Studio_C4, Studio_C5, 12, 30, Width - 24, 30);

            DrawBorders(Studio_P2, Studio_RT1);
            DrawBorders(Studio_P3, 14, 32, Width - 26, Height - 12 - 32);

            DrawText(Studio_B2, HorizontalAlignment.Left, 12, 0);

            DrawBorders(Studio_P4, 1);

            G.ResetClip();
            G.DrawPath(Studio_P5, Studio_Path);
        }
コード例 #12
0
        private void MainForm_Paint(object sender, PaintEventArgs e)
        {
            Graphics g       = e.Graphics;
            int      yOffSet = 10;
            // Get all members of the HatchStyle enum.
            Array obj = Enum.GetValues(typeof(HatchStyle));

            // Draw an oval with first 5 HatchStyle values.
            for (int x = 0; x < 5; x++)
            {
                // Configure Brush.
                HatchStyle temp     = (HatchStyle)obj.GetValue(x);
                HatchBrush theBrush = new HatchBrush(temp,
                                                     Color.White, Color.Black);
                // Print name of HatchStyle enum.
                g.DrawString(temp.ToString(), new Font("Times New Roman", 10),
                             Brushes.Black, 0, yOffSet);
                // Fill a rectangle with the correct brush.
                g.FillEllipse(theBrush, 150, yOffSet, 200, 25);
                yOffSet += 40;
            }
        }
コード例 #13
0
        /// <summary>
        /// Returns Brush representation of given Brush string,
        /// if the brush was a <see cref="SolidBrush"/>, <see cref="TextureBrush"/>,
        /// or <see cref="HatchBrush"/>.
        /// </summary>
        /// <remarks>All other Brushtypes are currently not serializable.</remarks>
        /// <param name="str">string with brush description.</param>
        /// <returns>A <see cref="SolidBrush"/>, <see cref="TextureBrush"/>,
        /// or <see cref="HatchBrush"/> or null if string is empty.</returns>
        public static Brush StringToBrush(string str)
        {
            if (str == string.Empty)
            {
                return(null);
            }

            string delim = ";";

            string[] parts = str.Trim().Split(delim.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            Brush    newValue;

            if (parts[0] == "SolidBrush")
            {
                newValue = new SolidBrush(HtmlAlphaToColor(parts[1]));
            }
            else if (parts[0] == "TextureBrush")
            {
                string[] majorParts = str.Split(new string[] { "<bmpbytes>" }, StringSplitOptions.RemoveEmptyEntries);
                parts = majorParts[0].Trim().Split(delim.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                WrapMode mode     = (WrapMode)Enum.Parse(typeof(WrapMode), parts[1]);
                byte[]   btmBytes = Convert.FromBase64String(majorParts[1]);
                Image    bitmap   = new Bitmap(new System.IO.MemoryStream(btmBytes));
                newValue = new TextureBrush(bitmap, mode);
            }
            else if (parts[0] == "HatchBrush")
            {
                HatchStyle style      = (HatchStyle)Enum.Parse(typeof(HatchStyle), parts[1]);
                Color      foreground = HtmlAlphaToColor(parts[2]);
                Color      background = HtmlAlphaToColor(parts[3]);
                newValue = new HatchBrush(style, foreground, background);
            }
            else
            {
                newValue = SystemBrushes.ButtonHighlight;
            }

            return(newValue);
        }
コード例 #14
0
ファイル: SoundEditor.cs プロジェクト: DmitriiKostrov/Voice
 public SoundEditor(Control parent)
 {
     this.Parent = parent;
     InitializeComponent();
     SrcPic.Init(parent);
     ResultPic.Init(parent);
     // pixels per second
     ToolButton100MS.Tag = 1000;
     ToolButton1S.Tag    = 100;
     ToolButton10S.Tag   = 10;
     initPanels();
     SrcPic.Location          = new Point(8, 2);
     ResultPic.Location       = new Point(8, 2);
     SrcPic.RememberEvent    += new EventHandler(OnRememberEvent);
     ResultPic.RememberEvent += new EventHandler(OnRememberEvent);
     SrcPic.SaveEvent        += new EventHandler(Pic_SaveEvent);
     ResultPic.SaveEvent     += new EventHandler(Pic_SaveEvent);
     ResultPic.Name           = "";
     _colors      = new Color[] { Color.Violet, Color.LimeGreen, Color.Blue, Color.Orange, Color.DarkTurquoise, Color.Red };
     _brushChoose = new HatchBrush(HatchStyle.Percent10, Color.Orange, Color.Transparent);
     _storedParts = new List <WavePanel>();
 }
コード例 #15
0
        private static void scheduler_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e)
        {
            SchedulerControl               scheduler       = sender as SchedulerControl;
            AppointmentViewInfo            viewInfo        = (e.ObjectInfo as DevExpress.XtraScheduler.Drawing.AppointmentViewInfo);
            Appointment                    apt             = viewInfo.Appointment;
            AppointmentBaseCollection      allAppointments = scheduler.ActiveView.GetAppointments();
            AppointmentConflictsCalculator aCalculator     = new AppointmentConflictsCalculator(allAppointments);
            TimeInterval                   visibleInterval = scheduler.ActiveView.GetVisibleIntervals().Interval;
            bool isConflict = aCalculator.CalculateConflicts(apt, visibleInterval).Count != 0;

            // Paint conflict appointments with a red and white hatch brush.
            if (isConflict)
            {
                Rectangle rect  = e.Bounds;
                Brush     brush = e.Cache.GetSolidBrush(scheduler.DataStorage.Appointments.Labels.GetById(apt.LabelKey).GetColor());
                e.Cache.FillRectangle(brush, rect);
                rect.Inflate(-3, -3);
                using (var _hatchBrush = new HatchBrush(HatchStyle.WideUpwardDiagonal, Color.Red, Color.White))
                    e.Cache.FillRectangle(_hatchBrush, rect);
                e.Handled = true;
            }
        }
コード例 #16
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (this.DesignMode)
            {
                if (this.glassFrame.Enabled)
                {
                    HatchBrush aeroBrush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Navy, this.BackColor);
                    if (this.glassFrame.SheetOfGlass)
                    {
                        e.Graphics.FillRectangle(aeroBrush, this.ClientRectangle);
                    }
                    else
                    {
                        if (glassFrame.Left > 0)
                        {
                            e.Graphics.FillRectangle(aeroBrush, new Rectangle(0, 0, glassFrame.Left, ClientRectangle.Height));
                        }

                        if (glassFrame.Top > 0)
                        {
                            e.Graphics.FillRectangle(aeroBrush, new Rectangle(0, 0, ClientRectangle.Width, glassFrame.Top));
                        }

                        if (glassFrame.Right > 0)
                        {
                            e.Graphics.FillRectangle(aeroBrush, new Rectangle(ClientRectangle.Width - glassFrame.Right,
                                                                              0, glassFrame.Right, ClientRectangle.Height));
                        }

                        if (glassFrame.Bottom > 0)
                        {
                            e.Graphics.FillRectangle(aeroBrush, new Rectangle(0, ClientRectangle.Bottom - glassFrame.Bottom,
                                                                              Width, glassFrame.Bottom));
                        }
                    }
                }
            }
        }
        public static void Run()
        {
            // ExStart:DrawingUsingGraphicsPath
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();

            // Create an instance of BmpOptions and set its various properties
            BmpOptions ImageOptions = new BmpOptions();
            ImageOptions.BitsPerPixel = 24;

            // Create an instance of FileCreateSource and assign it to Source property
            ImageOptions.Source = new FileCreateSource(dataDir + "sample_1.bmp", false);

            // Create an instance of Image and initialize an instance of Graphics
            using (Image image = Image.Create(ImageOptions, 500, 500))
            {
                Graphics graphics = new Graphics(image);
                graphics.Clear(Color.White);

                // Create an instance of GraphicsPath and Instance of Figure, add EllipseShape, RectangleShape and TextShape to the figure
                GraphicsPath graphicspath = new GraphicsPath();
                Figure figure = new Figure();
                figure.AddShape(new EllipseShape(new RectangleF(0, 0, 499, 499)));
                figure.AddShape(new RectangleShape(new RectangleF(0, 0, 499, 499)));
                figure.AddShape(new TextShape("Aspose.Imaging", new RectangleF(170, 225, 170, 100), new Font("Arial", 20), StringFormat.GenericTypographic));
                graphicspath.AddFigures(new[] { figure });
                graphics.DrawPath(new Pen(Color.Blue), graphicspath);

                // Create an instance of HatchBrush and set its properties also Fill path by supplying the brush and GraphicsPath objects
                HatchBrush hatchbrush = new HatchBrush();
                hatchbrush.BackgroundColor = Color.Brown;
                hatchbrush.ForegroundColor = Color.Blue;
                hatchbrush.HatchStyle = HatchStyle.Vertical;
                graphics.FillPath(hatchbrush, graphicspath);
                image.Save();
                Console.WriteLine("Processing completed successfully.");
            }
            // ExEnd:DrawingUsingGraphicsPath
        }
コード例 #18
0
    protected override void OnPaint(PaintEventArgs e)
    {
        Graphics graphics = e.Graphics;

        graphics.SmoothingMode     = SmoothingMode.HighQuality;
        graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
        base.OnPaint(e);
        graphics.Clear(Color.White);
        using (Pen pen = new Pen(Helpers.ColorFromHex("#D0D5D9")))
        {
            graphics.DrawPath(pen, Helpers.RoundRect(Helpers.FullRectangle(base.Size, true), 0, Helpers.RoundingStyle.All));
        }
        bool flag = this.Value != 0;

        if (flag)
        {
            using (HatchBrush hatchBrush = new HatchBrush(HatchStyle.LightUpwardDiagonal, this.Stripes, this.BackgroundColor))
            {
                graphics.FillPath(hatchBrush, Helpers.RoundRect(checked (new Rectangle(0, 0, (int)Math.Round(unchecked ((double)this.Value / (double)this.Maximum * (double)base.Width - 1.0)), base.Height - 1)), 0, Helpers.RoundingStyle.All));
            }
        }
    }
コード例 #19
0
        private void DrawLayerColliders(Graphics g, TmxLayer layer, Color polyColor, Color lineColor)
        {
            LayerClipper.TransformPointFunc xfFunc   = (x, y) => new ClipperLib.IntPoint(x, y);
            LayerClipper.ProgressFunc       progFunc = (prog) => { }; // do nothing

            ClipperLib.PolyTree solution = LayerClipper.ExecuteClipper(this.tmxMap, layer, xfFunc, progFunc);

            using (GraphicsPath path = new GraphicsPath())
                using (Pen pen = new Pen(lineColor, 1.0f))
                    using (Brush brush = new HatchBrush(HatchStyle.ForwardDiagonal, lineColor, polyColor))
                    {
                        pen.Alignment = PenAlignment.Inset;

                        // Draw all closed polygons
                        foreach (var points in ClipperLib.Clipper.ClosedPathsFromPolyTree(solution))
                        {
                            var pointfs = points.Select(pt => new PointF(pt.X, pt.Y));
                            path.AddPolygon(pointfs.ToArray());
                        }
                        if (path.PointCount > 0)
                        {
                            g.FillPath(brush, path);
                            g.DrawPath(pen, path);
                        }

                        // Draw all lines (open polygons)
                        path.Reset();
                        foreach (var points in ClipperLib.Clipper.OpenPathsFromPolyTree(solution))
                        {
                            var pointfs = points.Select(pt => new PointF(pt.X, pt.Y));
                            path.StartFigure();
                            path.AddLines(pointfs.ToArray());
                        }
                        if (path.PointCount > 0)
                        {
                            g.DrawPath(pen, path);
                        }
                    }
        }
コード例 #20
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Bitmap    B      = new Bitmap(Width, Height);
            Graphics  G      = Graphics.FromImage(B);
            Rectangle TopBar = new Rectangle(0, 0, Width - 1, 30);
            Rectangle Body   = new Rectangle(0, 10, Width - 1, Height - 1);

            base.OnPaint(e);

            G.Clear(Color.Fuchsia);

            //G.SmoothingMode = SmoothingMode.HighQuality

            LinearGradientBrush lbb       = new LinearGradientBrush(Body, Color.FromArgb(19, 19, 19), Color.FromArgb(17, 17, 17), 90);
            HatchBrush          bodyhatch = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(20, 20, 20), Color.Transparent);

            G.FillPath(lbb, Draw.RoundRect(Body, 5));
            G.FillPath(bodyhatch, Draw.RoundRect(Body, 5));
            G.DrawPath(Pens.Black, Draw.RoundRect(Body, 5));


            LinearGradientBrush lgb = new LinearGradientBrush(TopBar, Color.FromArgb(60, 60, 62), Color.FromArgb(25, 25, 25), 90);

            //Dim tophatch As New HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(20, 20, 20), Color.Transparent)
            G.FillPath(lgb, Draw.RoundRect(TopBar, 4));
            //G.FillPath(tophatch, Draw.RoundRect(TopBar, 4))
            G.DrawPath(Pens.Black, Draw.RoundRect(TopBar, 4));
            G.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(33, 0, Width - 1, 30), new StringFormat
            {
                Alignment     = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            });

            G.DrawIcon(Parent.FindForm().Icon, new Rectangle(11, 8, 16, 16));

            e.Graphics.DrawImage((Bitmap)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
コード例 #21
0
        /// <summary>
        /// Invisible objects only have x, y, width, heightr simply add a rectangle
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="g"></param>
        /// <returns></returns>
        private bool DrawInvisibleObject(CObject obj, Graphics g)
        {
            int x, y, width, height;

            // don't draw object of another section
            try
            {
                if (obj.GetProperty(Utils.SpecialProp_Section).EncodedValue != Section.StringId)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            try { x = int.Parse(obj.GetProperty(Utils.SpecialProp_X).EncodedValue); }
            catch { return(false); }

            try { y = int.Parse(obj.GetProperty(Utils.SpecialProp_Y).EncodedValue); }
            catch { return(false); }

            try { width = int.Parse(obj.GetProperty(Utils.SpecialProp_Width).EncodedValue); }
            catch { return(false); }

            try { height = int.Parse(obj.GetProperty(Utils.SpecialProp_Height).EncodedValue); }
            catch { return(false); }

            Pen pen = new Pen(Color.Beige, 1);
            // Brush brush = new SolidBrush(Color.FromArgb(50, Color.Beige));

            Brush brush = new HatchBrush(HatchStyle.DiagonalCross, Color.FromArgb(50, Color.Beige), Color.FromArgb(200, Color.Black));

            g.FillRectangle(brush, ScaleRectangle(x, y, width, height, 1));
            g.DrawRectangle(pen, ScaleRectangle(x, y, width, height, 1));

            return(true);
        }
コード例 #22
0
        protected override void PaintHook()
        {
            G.Clear(BackColor);
            G.SmoothingMode = SmoothingMode.HighQuality;

            //HatchBrush
            HatchBrush HB = new HatchBrush(HatchStyle.Percent20, Color.FromArgb(83, 83, 83), BackColor);

            G.FillRectangle(HB, new Rectangle(0, 0, Width, Height));

            if (_Checked)
            {
                if (State == MouseState.Over & X <= 11)
                {
                    G.FillEllipse(new SolidBrush(Color.FromArgb(100, 100, 100)), new Rectangle(0, 3, 11, 11));
                }
                else
                {
                    G.FillEllipse(new SolidBrush(Color.FromArgb(95, 95, 95)), new Rectangle(0, 3, 11, 11));
                }
                G.FillEllipse(new SolidBrush(Color.FromArgb(214, 214, 214)), new Rectangle(3, 6, 5, 5));
                G.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(68, 68, 68))), new Rectangle(0, 3, 11, 11));
            }
            else
            {
                if (State == MouseState.Over & X <= 11)
                {
                    G.FillEllipse(new SolidBrush(Color.FromArgb(94, 94, 94)), new Rectangle(0, 3, 11, 11));
                    G.FillEllipse(new SolidBrush(Color.FromArgb(88, 88, 88)), new Rectangle(2, 5, 8, 9));
                }
                else
                {
                    G.FillEllipse(new SolidBrush(Color.FromArgb(89, 89, 89)), new Rectangle(0, 3, 11, 11));
                    G.FillEllipse(new SolidBrush(Color.FromArgb(83, 83, 83)), new Rectangle(2, 5, 8, 9));
                }
                G.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(68, 68, 68))), new Rectangle(0, 3, 11, 11));
            }
            G.DrawString(Text, Font, TextBrush, new Point(17, 2));
        }
        private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            GridView        view     = (GridView)sender;
            GridViewInfo    viewInfo = (GridViewInfo)view.GetViewInfo();
            GridColumnsInfo ci       = viewInfo.ColumnsInfo;

            if (!view.IsDataRow(e.RowHandle) || e.RowHandle == view.FocusedRowHandle ||
                ci.FirstColumnInfo.Column != e.Column)
            {
                return;
            }
            bool       even   = e.RowHandle % 2 == 0;
            HatchStyle hStyle = even ? HatchStyle.BackwardDiagonal : HatchStyle.Cross;
            Color      fColor = even ? Color.AliceBlue : Color.AntiqueWhite;
            Color      bColor = even ? Color.Aqua : Color.Aquamarine;
            Rectangle  row    = new Rectangle(viewInfo.ViewRects.Rows.Left, e.Bounds.Y,
                                              viewInfo.ViewRects.Rows.Width, e.Bounds.Height);

            using (Brush brush = new HatchBrush(hStyle, fColor, bColor)) {
                e.Cache.FillRectangle(brush, row);
            }
        }
コード例 #24
0
        public static void DrawFrame(Graphics g, Region resizeBorder, FrameStyle style, Color backColor)
        {
            Brush brush;
            Color controlDarkDark = SystemColors.ControlDarkDark;

            if ((backColor != Color.Empty) && (backColor.GetBrightness() < 0.5))
            {
                controlDarkDark = SystemColors.ControlLight;
            }
            switch (style)
            {
            case FrameStyle.Dashed:
                brush = new HatchBrush(HatchStyle.Percent50, controlDarkDark, Color.Transparent);
                break;

            default:
                brush = new SolidBrush(controlDarkDark);
                break;
            }
            g.FillRegion(brush, resizeBorder);
            brush.Dispose();
        }
コード例 #25
0
        protected override void PaintHook()
        {
            G.Clear(BG);
            G.SmoothingMode = SmoothingMode.HighQuality;
            if (_Checked)
            {
                LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(9, 9)), G1, G2, 90f);
                G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(9, 9)));
                G.FillEllipse(new SolidBrush(Glow), new Rectangle(new Point(0, 0), new Size(9, 4)));
            }
            else
            {
                LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(9, 11)), G1, G2, 90f);
                G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(9, 9)));
                G.FillEllipse(new SolidBrush(Glow), new Rectangle(new Point(0, 0), new Size(9, 4)));
            }

            if (State == MouseState.Over & X < 15)
            {
                SolidBrush SB = new SolidBrush(Color.FromArgb(70, Color.White));
                G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(9, 9)));
            }
            else if (State == MouseState.Down & X < 15)
            {
                SolidBrush SB = new SolidBrush(Color.FromArgb(10, Color.Black));
                G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(9, 9)));
            }

            HatchBrush HB = new HatchBrush(HatchStyle.LightDownwardDiagonal, Color.FromArgb(7, Color.Black), Color.Transparent);

            G.FillEllipse(HB, new Rectangle(new Point(0, 0), new Size(9, 9)));
            G.DrawEllipse(new Pen(Edge), new Rectangle(new Point(0, 0), new Size(9, 9)));

            if (_Checked)
            {
                G.FillEllipse(GetBrush("Bullet"), new Rectangle(new Point(2, 2), new Size(5, 5)));
            }
            DrawText(new SolidBrush(TextColor), HorizontalAlignment.Left, 19, -1);
        }
コード例 #26
0
ファイル: Renderer.cs プロジェクト: TagruP/tpd
        private void DrawRect(Rectangle rect, Color insideColor, Color borderColor, bool offsetForPen = false, bool hatch = false)
        {
            Brush fillBrush = new SolidBrush(insideColor);

            if (hatch)
            {
                fillBrush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.White, insideColor);
            }

            Pen outlinePen = new Pen(borderColor);

            graphics.FillRectangle(fillBrush, rect);

            if (offsetForPen)
            {
                graphics.DrawRectangle(outlinePen, rect.X, rect.Y, rect.Width - outlinePen.Width, rect.Height - outlinePen.Width);
            }
            else
            {
                graphics.DrawRectangle(outlinePen, rect.X, rect.Y, rect.Width, rect.Height);
            }
        }
コード例 #27
0
        HatchBrush GetHatchBrush()
        {
            string hsStr = GetValue("hs");
            string cStr  = GetValue("c");
            string c2Str = GetValue("c2");

            if (hsStr == null || cStr == null)
            {
                return(null);
            }
            object hsObj = base.GetEnum(typeof(HatchStyle), hsStr, "hs");

            if (hsObj == null)
            {
                return(null);
            }
            HatchStyle hs = (HatchStyle)hsObj;
            Color      c  = GetColor(cStr, "c");

            if (c.ToArgb() == 0)
            {
                return(null);
            }
            HatchBrush hb = null;

            if (c2Str != null)
            {
                Color c2 = GetColor(c2Str, "c2");
                if (c2.ToArgb() != 0)
                {
                    hb = new HatchBrush(hs, c, c2);
                }
            }
            if (hb == null)
            {
                hb = new HatchBrush(hs, c);
            }
            return(hb);
        }
コード例 #28
0
ファイル: SssDrawing.cs プロジェクト: zfybs/SocketedPiles
        /// <summary> 绘制图形 </summary>
        /// <param name="g">用于绘图的Graphics对象</param>
        private static void DrawShapes(Graphics g)
        {
            HatchBrush hb = new HatchBrush(HatchStyle.LightUpwardDiagonal, Color.Black, Color.White);

            g.FillEllipse(Brushes.Gray, 10f, 10f, 200, 200);
            g.DrawEllipse(new Pen(Color.Black, 1f), 10f, 10f, 200, 200);
            g.FillEllipse(hb, 30f, 95f, 30, 30);
            g.DrawEllipse(new Pen(Color.Black, 1f), 30f, 95f, 30, 30);
            g.FillEllipse(hb, 160f, 95f, 30, 30);
            g.DrawEllipse(new Pen(Color.Black, 1f), 160f, 95f, 30, 30);
            g.FillEllipse(hb, 95f, 30f, 30, 30);
            g.DrawEllipse(new Pen(Color.Black, 1f), 95f, 30f, 30, 30);
            g.FillEllipse(hb, 95f, 160f, 30, 30);
            g.DrawEllipse(new Pen(Color.Black, 1f), 95f, 160f, 30, 30);
            g.FillEllipse(Brushes.Blue, 60f, 60f, 100, 100);
            g.DrawEllipse(new Pen(Color.Black, 1f), 60f, 60f, 100, 100);
            g.FillEllipse(Brushes.BlanchedAlmond, 95f, 95f, 30, 30);
            g.DrawEllipse(new Pen(Color.Black, 1f), 95f, 95f, 30, 30);
            g.DrawRectangle(new Pen(Brushes.Blue, 0.1f), 6, 6, 208, 208);
            g.DrawLine(new Pen(Color.Black, 0.1f), 110f, 110f, 220f, 25f);
            g.DrawString("剖面图", new Font("宋体", 9f), Brushes.Green, 220f, 20f);
        }
コード例 #29
0
 private void colorListBox_DrawItem(object sender, DrawItemEventArgs e)
 {
     if (e.Index < 0)
     {
         return;
     }
     var color = (Color) colorListBox.Items[e.Index];
     if ((e.State & DrawItemState.Selected) == 0)
     {
         using (var brush = new SolidBrush(color))
         {
             e.Graphics.FillRectangle(brush, e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Width - 2, e.Bounds.Height - 1);
         }
     }
     else
     {
         using (var brush = new HatchBrush(HatchStyle.Percent70, color, Color.Gray))
         {
             e.Graphics.FillRectangle(brush, e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Width - 2, e.Bounds.Height - 1);
         }
     }
 }
コード例 #30
0
        public void DrawScene(Graphics g)
        {
            // declare a brush object to be passed through functions and used
            // for coloing
            Brush brush = new SolidBrush(Color.Black);

            // draw text
            g.DrawString("Relax and stay a while", new
                         System.Drawing.Font("Times New Roman", 32), brush, 50, 50);
            // get the waterfall x offset, that is, 1 / 2 of the waterfall width
            int waterfallXOffset = (int)(Size.Width * (1 / 5.0));
            // get the center of the waterfall x
            int waterfallXCenter = (int)(Size.Width * (1 / 2.0));
            int groundY          = (int)((7 / 11.0) * Size.Height);

            // draw tree
            DrawTree(g, brush, waterfallXCenter + waterfallXOffset + 25,
                     (int)(groundY * (1 / 17.0)), (int)(Size.Width * (23 / 24.0)),
                     groundY, 13);
            // draw bridge
            DrawBridge(g, brush, waterfallXCenter, waterfallXOffset, groundY);
            // get a brush that is the color of the ground
            brush = new SolidBrush(Color.SaddleBrown);
            // Draw the ground
            g.FillRectangle(brush, Location.X, groundY, Size.Width,
                            Size.Height - groundY);
            // get a brush that is the color of the waterfall stream
            brush = new HatchBrush(HatchStyle.Wave, Color.MintCream, Color.Aqua);
            // draw the waterfall
            g.FillRectangle(brush, waterfallXCenter - waterfallXOffset, groundY - 3,
                            2 * waterfallXOffset, Size.Height + 3 - groundY);
            // make a pen for the stick figure
            Pen p = new Pen(Color.Black, 2);

            // draw person laying against tree
            DrawStickFigure(g, p, waterfallXCenter + waterfallXOffset + 65,
                            groundY - 35, waterfallXCenter + waterfallXOffset + 65 + 85,
                            groundY);
        }
コード例 #31
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;

            base.BringToFront();
            if (base.Opacity < 1.0)
            {
                base.Opacity = 1.0;
            }
            if (this.targetHost != null)
            {
                Bitmap bmpDockAll = OverlayForm.bmpDockAll;
                if (!this.targetHost.AllowSplit)
                {
                    bmpDockAll = bmpDockCenter;
                }
                int x = (base.Width / 2) - (bmpDockAll.Width / 2);
                int y = (base.Height / 2) - (bmpDockAll.Height / 2);
                graphics.DrawImageUnscaled(bmpDockAll, new Point(x, y));
            }
            else
            {
                Pen       pen;
                Rectangle clientRectangle = base.ClientRectangle;
                if ((DockManager.Style == DockVisualStyle.VS2003) | DockManager.FastMoveDraw)
                {
                    HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.FromArgb(5, 5, 5), base.TransparencyKey);
                    pen = new Pen(brush, 6f);
                }
                else
                {
                    base.Opacity = 0.4;
                    graphics.Clear(Color.FromArgb(0x68, 10, 0x24, 0x6a));
                    pen = new Pen(SystemColors.Control, 2f);
                    clientRectangle.Inflate(-1, -1);
                }
                graphics.DrawRectangle(pen, clientRectangle);
            }
        }
コード例 #32
0
 void timer_Tick(object sender, EventArgs e)
 {
     if (!_player.IsPlaying)
     {
         stopPlay();
     }
     else
     {
         // play position line
         // 44100 by 16 bit. and devide by resolution
         int      linePos = (int)Math.Round(((double)_player.PlayPosition - AudioUtils.WavHeadSize) / ((double)44100 * 2 / (double)_resolution));
         Bitmap   img     = (Bitmap)_img.Clone();
         Graphics g       = Graphics.FromImage(img);
         Brush    brush   = new HatchBrush(HatchStyle.SolidDiamond, Color.Orange, Color.Transparent);
         Pen      pen     = new Pen(Color.Black, 1);
         g.DrawRectangle(pen, linePos, 0, 3, img.Height - 1);
         g.FillRectangle(brush, linePos + 1, 1, 2, img.Height - 2);
         //g.DrawLine(pen, linePos, 0, linePos, img.Height);
         g.Dispose();
         PictureBox.Image = img;
     }
 }
コード例 #33
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            this.SetClientSizeCore(500, 600);
            Graphics   g = e.Graphics;
            HatchBrush brush;
            int        x = 20;
            int        y = 20;

            foreach (HatchStyle brushStyle in Enum.GetValues(typeof(HatchStyle)))
            {
                brush = new HatchBrush(brushStyle, Color.Navy, Color.Yellow);
                g.FillRectangle(brush, x, y, 40, 20);
                y += 30;
                if ((y + 30) > this.ClientSize.Height)
                {
                    y  = 20;
                    x += 150;
                }
            }

            g.Dispose();
        }
コード例 #34
0
        /// <summary>
        /// Begin a tracking indicator in the specified control using the specified rectangle.
        /// </summary>
        ///	<param name="control">The control into which the tracking indicator will be drawn.</param>
        /// <param name="rectangle">Rectangle structure that represents the tracking indicator rectangle, relative to the upper-left corner of the control into which it will be drawn.</param>
        public void Begin(Control control, Rectangle rectangle)
        {
            //	Can't Begin twice.
            Debug.Assert(!valid, "Invalid nested Begin", "You must first call the End method of a VerticalTrackingIndicator before calling its Begin method again.");
            if (valid)
            {
                End();
            }

            //	Save away the control.  We need this so we can call ReleaseDC later on.
            this.control = control;

            //	Get a DC for the "visible region" the specified control.  Children are not clipped
            //	for this DC, which allows us to draw the tracking indicator over them.
            controlDC = GetDCEx(control.Handle, System.IntPtr.Zero, DCX_PARENTCLIP);

            //	Get a graphics object for the DC.
            controlGraphics = Graphics.FromHdc(controlDC);

            //	Instantiate the capture bitmap.
            captureBitmap = new Bitmap(rectangle.Width, rectangle.Height);

            //	Instantiate and paint the tracking indicator bitmap.
            trackingIndicatorBitmap = new Bitmap(rectangle.Width, rectangle.Height);
            Graphics   trackingIndicatorBitmapGraphics = Graphics.FromImage(trackingIndicatorBitmap);
            HatchBrush hatchBrush = new HatchBrush(HatchStyle.Percent50,
                                                   Color.FromArgb(128, Color.Black),
                                                   Color.FromArgb(128, Color.White));

            trackingIndicatorBitmapGraphics.FillRectangle(hatchBrush, new Rectangle(0, 0, rectangle.Width, rectangle.Height));
            hatchBrush.Dispose();
            trackingIndicatorBitmapGraphics.Dispose();

            //	Draw the new tracking indicator.
            DrawTrackingIndicator(rectangle.Location);

            //	Valid now.
            valid = true;
        }
コード例 #35
0
ファイル: FormsHello.cs プロジェクト: hitswa/winforms
	private void HandlePaint(Object sender, PaintEventArgs e)
	{
		Graphics graphics = e.Graphics;
		Form form = (sender as Form);
		Rectangle bounds = form.ClientRectangle;

		Pen pen = new Pen(Color.Black, 1.0f);
		graphics.DrawLine(pen, 0, 0, bounds.Width, bounds.Height - 23);
		pen.Dispose();

		pen = new Pen(Color.Red, 2.0f);
		graphics.DrawRectangle
			(pen, 10, 10, bounds.Width - 20, bounds.Height - 40);
		pen.Dispose();

		ControlPaint.DrawFocusRectangle
			(graphics,
			 new Rectangle(15, 15, bounds.Width - 30, bounds.Height - 50));

		Brush brush = new SolidBrush(Color.Yellow);
		graphics.FillPie(brush, 20, 20, 60, 60, 30.0f, 70.0f);
		brush.Dispose();

		Font font = new Font("Arial", 12);
		brush = new SolidBrush(Color.Blue);
		graphics.DrawString("Hello", font, brush, 30, 100);
		brush.Dispose();
		font.Dispose();

		brush = new HatchBrush
			(HatchStyle.BackwardDiagonal, Color.Black, Color.White);
		graphics.FillEllipse(brush, 200, 40, 100, 100);
		brush.Dispose();
	}
コード例 #36
0
ファイル: GDI.cs プロジェクト: ChrisMoreton/Test3
		/// <summary>
		/// Creates and returns a new brush,
		/// given its string representation.
		/// </summary>
		public static Brush Deserialize(string image)
		{
			Brush brush = null;

			int semicolon = image.IndexOf(";");
			if (semicolon == -1)
				return null;

			string code = image.Substring(0, semicolon);
			string representation = image.Substring(semicolon + 1);

			switch (code)
			{

				case "solid":
					brush = new SolidBrush(Color.Black);
					break;

				case "hatch":
					brush = new HatchBrush(HatchStyle.Cross, Color.Black);
					break;

				case "gradient":
					brush = new LinearGradientBrush(Color.Black, Color.Black);
					break;

				case "texture":
					brush = new TextureBrush((Image)null);
					break;

			}

			if (brush == null)
				return null;

			brush.Restore(representation);

			return brush;
		}
コード例 #37
0
ファイル: CardGenerator.cs プロジェクト: rivdiv/play-set
    public void GenerateCardImages()
    {
        int s = 10;
        int h = 100;
        int w = 300;
        foreach (var card in Card.GetCards())
        {
            var img = new Bitmap(w, w);
            var graphics = Graphics.FromImage(img);
            graphics.Clear(Color.White);

            Brush brush;
            if (card.Fill == Card.Fills.Solid.ToString())
            {
                brush = new SolidBrush(card.Color);
            }
            else if (card.Fill == Card.Fills.Striped.ToString())
            {
                brush = new HatchBrush(HatchStyle.WideUpwardDiagonal, Color.White, card.Color);
            }
            else
            {
                brush = new SolidBrush(Color.White);
            }

            // shape
            Rectangle[] rectangles = new Rectangle[card.Number];
            for (int i = 0; i < card.Number; i++)
            {
                int x = s;
                int width = w - (s * 2);
                int y = (i * h) + s;
                int height = h - (s * 2);
                var rectangle = new Rectangle(x, y, width, height);
                if (card.Shape == Card.Shapes.Rectangle.ToString())
                {
                    rectangles[i] = rectangle;

                    if (card.Fill == Card.Fills.Empty.ToString())
                    {
                        if (rectangles.Count() > 0)
                        {
                            graphics.DrawRectangle(new Pen(card.Color), rectangle);
                        }
                    }
                    else
                    {
                        graphics.FillRectangle(brush, rectangle);
                    }
                }
                else if (card.Shape == Card.Shapes.Oval.ToString())
                {
                    if (card.Fill == Card.Fills.Empty.ToString())
                    {
                        graphics.DrawEllipse(new Pen(card.Color), rectangle);
                    }
                    else
                    {
                        graphics.FillEllipse(brush, rectangle);
                    }
                }
                else if (card.Shape == Card.Shapes.Diamond.ToString())
                {
                    var sp = i == 0 ? s : s * 2;
                    var x1 = width;
                    var y1 = (height / 2) + (h * i);
                    var x2 = (width / 2);
                    var y2 = i * height;
                    var x3 = s / 2;
                    var y3 = (height / 2) + (h * i);
                    var x4 = width / 2;
                    // var y4 =(height * (i+1));
                    var y4 = y1 + (height / 2);
                    var points = new Point[]{
                           new Point(x1 + s, y1  - (s*i)+ sp - s),
                           new Point(x2 + s, y2+ (s* (i+1))+ sp-s),
                           new Point(x3, y3  - (s*i)+ sp-s ),
                           new Point(x4 + s, y4 - (s*i)+ sp-s)
                        };

                    if (card.Fill == Card.Fills.Empty.ToString())
                    {
                        graphics.DrawPolygon(new Pen(card.Color), points);
                    }
                    else
                    {
                        graphics.FillPolygon(brush, points);
                    }
                }
            }

            var path = string.Format("~/Images/Cards/SetImage-{0}.png", card.CardID);
            img.RotateFlip(RotateFlipType.Rotate90FlipNone);
            img.Save(HttpContext.Current.Server.MapPath(path), ImageFormat.Png);
        }
    }
コード例 #38
0
ファイル: W31Button.cs プロジェクト: wyrover/SuperCMD
 public Bitmap toBmp()
 {
     Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
     Graphics g = Graphics.FromImage(bmp);
     if (this.Parent != null)
     {
         g.Clear(this.Parent.BackColor);
     }
     else
     {
         g.Clear(ParentBgColor);
     }
     // Prepare
     maxX = this.ClientSize.Width - 1;
     maxY = this.ClientSize.Height - 1;
     contentRect = new Rectangle(4, 4, maxX - 4 - 3, maxY - 4 - 3);
     contentRect.X += this.Padding.Left;
     contentRect.Y += this.Padding.Top;
     contentRect.Width -= this.Padding.Right;
     contentRect.Height -= this.Padding.Bottom;
     Int32 txtAgnNum = (Int32)Math.Log((Double)this.TextAlign, 2);
     sf.LineAlignment = (StringAlignment)(txtAgnNum / 4);
     sf.Alignment = (StringAlignment)(txtAgnNum % 4);
     sf.HotkeyPrefix = HotkeyPrefix.Show;
     // Fill button color
     g.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(1, 1, maxX - 1, maxY - 1));
     if ((mDown & mOver) | mPress) g.TranslateTransform(1, 1);
     // Draw background image
     if (this.BackgroundImage != null)
     {
         int imgX = 0, imgY = 0;
         switch (this.BackgroundImageLayout)
         {
             case ImageLayout.Center:
                 imgX = (int)(contentRect.Width - this.BackgroundImage.Width) / 2;
                 imgY = (int)(contentRect.Height - this.BackgroundImage.Height) / 2;
                 imgX += contentRect.X;
                 imgY += contentRect.Y;
                 g.DrawImageUnscaled(this.BackgroundImage, imgX, imgY);
                 break;
             case ImageLayout.Stretch:
                 g.DrawImage(this.BackgroundImage, contentRect);
                 break;
             case ImageLayout.Tile:
                 g.FillRectangle(new TextureBrush(this.BackgroundImage, WrapMode.Tile), contentRect);
                 break;
             case ImageLayout.Zoom:
                 this.BackgroundImageLayout = ImageLayout.Stretch;
                 break;
             default: // assume as None
                 break;
         }
     }
     // Draw image
     if (this.Image != null)
     {
         int imgX = 0, imgY = 0;
         switch (this.ImageAlign)
         {
             case ContentAlignment.BottomCenter:
                 imgX = (int)(contentRect.Width - this.Image.Width) / 2;
                 imgY = contentRect.Height - this.Image.Height;
                 break;
             case ContentAlignment.BottomLeft:
                 imgY = contentRect.Height - this.Image.Height;
                 break;
             case ContentAlignment.BottomRight:
                 imgX = contentRect.Width - this.Image.Width;
                 imgY = contentRect.Height - this.Image.Height;
                 break;
             case ContentAlignment.MiddleLeft:
                 imgY = (int)(contentRect.Height - this.Image.Height) / 2;
                 break;
             case ContentAlignment.MiddleRight:
                 imgX = contentRect.Width - this.Image.Width;
                 imgY = (int)(contentRect.Height - this.Image.Height) / 2;
                 break;
             case ContentAlignment.TopCenter:
                 imgX = (int)(contentRect.Width - this.Image.Width) / 2;
                 break;
             case ContentAlignment.TopLeft:
                 break;
             case ContentAlignment.TopRight:
                 imgX = contentRect.Width - this.Image.Width;
                 break;
             default: // assume as MiddleCenter
                 imgX = (int)(contentRect.Width - this.Image.Width) / 2;
                 imgY = (int)(contentRect.Height - this.Image.Height) / 2;
                 break;
         }
         imgX += contentRect.X;
         imgY += contentRect.Y;
         g.DrawImageUnscaled(this.Image, imgX, imgY);
     }
     // Draw text
     Brush textBrush = new SolidBrush(this.ForeColor);
     if (!this.Enabled)
     {
         textBrush = new HatchBrush(HatchStyle.Percent50, this.ForeColor, this.BackColor);
     }
     g.DrawString(this.Text, this.Font, textBrush, contentRect, sf);
     g.ResetTransform();
     // Draw border
     if ((mDown & mOver) | mPress)
     {
         // Border (Top, Bottom, Left, Right)
         g.DrawLine(penBorder2, new Point(1, 1), new Point(maxX, 1));
         g.DrawLine(penBorder2, new Point(1, maxY), new Point(maxX, maxY));
         g.DrawLine(penBorder2, new Point(1, 1), new Point(1, maxY));
         g.DrawLine(penBorder2, new Point(maxX, 1), new Point(maxX, maxY));
         // Inner Border (Top)
         g.DrawLine(penInnerBorderTopLeft2, new Point(2, 2), new Point(this.ClientSize.Width - 3, 2));
         // Inner Border (Left)
         g.DrawLine(penInnerBorderTopLeft2, new Point(2, 2), new Point(2, this.ClientSize.Height - 3));
     }
     else if (this.Focused)
     {
         // Border (Top, Bottom, Left, Right)
         g.DrawLine(penBorder2, new Point(1, 1), new Point(maxX, 1));
         g.DrawLine(penBorder2, new Point(1, maxY), new Point(maxX, maxY));
         g.DrawLine(penBorder2, new Point(1, 1), new Point(1, maxY));
         g.DrawLine(penBorder2, new Point(maxX, 1), new Point(maxX, maxY));
         // Inner Border (Top)
         g.DrawLine(penInnerBorderTopLeft, new Point(2, 2), new Point(maxX - 2, 2));
         g.DrawLine(penInnerBorderTopLeft, new Point(2, 3), new Point(maxX - 3, 3));
         // Inner Border (Left)
         g.DrawLine(penInnerBorderTopLeft, new Point(2, 2), new Point(2, maxY - 2));
         g.DrawLine(penInnerBorderTopLeft, new Point(3, 2), new Point(3, maxY - 3));
         // Inner Border (Bottom)
         g.DrawLine(penInnerBorderBottomRight, new Point(3, maxY - 3), new Point(maxX - 3, maxY - 3));
         g.DrawLine(penInnerBorderBottomRight, new Point(2, maxY - 2), new Point(maxX - 2, maxY - 2));
         // Inner Border (Right)
         g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 3, 4), new Point(maxX - 3, maxY - 3));
         g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 2, 3), new Point(maxX - 2, maxY - 2));
     }
     else
     {
         // Border (Top, Bottom, Left, Right)
         g.DrawLine(penBorder, new Point(1, 0), new Point(maxX - 1, 0));
         g.DrawLine(penBorder, new Point(1, maxY), new Point(maxX - 1, maxY));
         g.DrawLine(penBorder, new Point(0, 1), new Point(0, maxY - 1));
         g.DrawLine(penBorder, new Point(maxX, 1), new Point(maxX, maxY - 1));
         // Inner Border (Top)
         g.DrawLine(penInnerBorderTopLeft, new Point(1, 1), new Point(maxX - 1, 1));
         g.DrawLine(penInnerBorderTopLeft, new Point(1, 2), new Point(maxX - 2, 2));
         // Inner Border (Left)
         g.DrawLine(penInnerBorderTopLeft, new Point(1, 1), new Point(1, maxY - 1));
         g.DrawLine(penInnerBorderTopLeft, new Point(2, 1), new Point(2, maxY - 2));
         // Inner Border (Bottom)
         g.DrawLine(penInnerBorderBottomRight, new Point(2, maxY - 2), new Point(maxX - 2, maxY - 2));
         g.DrawLine(penInnerBorderBottomRight, new Point(1, maxY - 1), new Point(maxX - 1, maxY - 1));
         // Inner Border (Right)
         g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 2, 3), new Point(maxX - 2, maxY - 2));
         g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 1, 2), new Point(maxX - 1, maxY - 1));
     }
     g.Dispose();
     return bmp;
 }
コード例 #39
0
    // ====================================================================
    // Creates the bitmap image.
    // ====================================================================
    private void GenerateImage()
    {
        // Create a new 32-bit bitmap image.
        Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb);

        // Create a graphics object for drawing.
        Graphics g = Graphics.FromImage(bitmap);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        Rectangle rect = new Rectangle(0, 0, this.width, this.height);

        // Fill in the background.
        HatchBrush hatchBrush = new HatchBrush(HatchStyle.OutlinedDiamond, Color.LightGray, Color.White);
        g.FillRectangle(hatchBrush, rect);

        // Set up the text font.
        SizeF size;
        float fontSize = rect.Height + 1;
        Font font;
        // Adjust the font size until the text fits within the image.
        do
        {
            fontSize--;
            font = new Font(this.familyName, fontSize, FontStyle.Strikeout);
            size = g.MeasureString(this.text, font);
        } while (size.Width > rect.Width);

        // Set up the text format.
        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;

        // Create a path using the text and warp it randomly.
        GraphicsPath path = new GraphicsPath();
        path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format);
        float v = 4F;
        PointF[] points =
            {
                new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
                new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
                new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
                new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
            };
        Matrix matrix = new Matrix();
        matrix.Translate(0F, 0F);
        path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

        // Draw the text.
        hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray);
        g.FillPath(hatchBrush, path);

        // Add some random noise.
        int m = Math.Max(rect.Width, rect.Height);
        for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
        {
            int x = this.random.Next(rect.Width);
            int y = this.random.Next(rect.Height);
            int w = this.random.Next(m / 50);
            int h = this.random.Next(m / 50);
            g.FillEllipse(hatchBrush, x, y, w, h);
        }

        // Clean up.
        font.Dispose();
        hatchBrush.Dispose();
        g.Dispose();

        // Set the image.
        this.image = bitmap;
    }
コード例 #40
0
 protected override void OnPaint(PaintEventArgs e)
 {
     this.G = e.Graphics;
     this.G.SmoothingMode = SmoothingMode.HighQuality;
     this.G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
     base.OnPaint(e);
     bool enabled = this.Enabled;
     if (enabled)
     {
         using (Pen pen = new Pen(Helpers.ColorFromHex("#C8C8C8")))
         {
             this.G.DrawEllipse(pen, new Rectangle(0, 0, 18, 18));
         }
         using (SolidBrush solidBrush = new SolidBrush(Helpers.ColorFromHex("#343843")))
         {
             this.G.DrawString(this.Text, new Font("Segoe UI", 9f), solidBrush, new Point(25, 1));
         }
         bool flag = this.State == Helpers.MouseState.Over | this.State == Helpers.MouseState.Down;
         if (flag)
         {
             using (Pen pen2 = new Pen(Helpers.ColorFromHex("#8C92A1")))
             {
                 this.G.DrawEllipse(pen2, new Rectangle(0, 0, 18, 18));
             }
         }
     }
     else
     {
         using (Pen pen3 = new Pen(Helpers.ColorFromHex("#DCDCDC")))
         {
             this.G.DrawEllipse(pen3, new Rectangle(0, 0, 18, 18));
         }
         using (SolidBrush solidBrush2 = new SolidBrush(Helpers.ColorFromHex("#989CA7")))
         {
             this.G.DrawString(this.Text, new Font("Segoe UI", 9f), solidBrush2, new Point(25, 1));
         }
     }
     bool @checked = this.Checked;
     if (@checked)
     {
         bool enabled2 = this.Enabled;
         if (enabled2)
         {
             using (HatchBrush hatchBrush = new HatchBrush(HatchStyle.WideUpwardDiagonal, Helpers.ColorFromHex("#5B606F"), Helpers.ColorFromHex("#525766")))
             {
                 using (Pen pen4 = new Pen(Helpers.ColorFromHex("#474C5A")))
                 {
                     this.G.FillEllipse(hatchBrush, new Rectangle(4, 4, 10, 10));
                     this.G.DrawEllipse(pen4, new Rectangle(4, 4, 10, 10));
                 }
             }
         }
         else
         {
             using (HatchBrush hatchBrush2 = new HatchBrush(HatchStyle.WideUpwardDiagonal, Helpers.ColorFromHex("#8C92A1"), Helpers.ColorFromHex("#7A7F8E")))
             {
                 using (Pen pen5 = new Pen(Helpers.ColorFromHex("#797E8C")))
                 {
                     this.G.FillEllipse(hatchBrush2, new Rectangle(4, 4, 10, 10));
                     this.G.DrawEllipse(pen5, new Rectangle(4, 4, 10, 10));
                 }
             }
         }
     }
 }
コード例 #41
0
        public static void Run()
        {
            // WmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it.  Create an instance of WmfRecorderGraphics2D class. The constructor takes in 2 parameters:  1. Instance of Imaging Rectangle class 2. An integer value for inches
            // ExStart:CreateWMFMetaFileImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
            WmfRecorderGraphics2D graphics = new WmfRecorderGraphics2D(new Rectangle(0, 0, 100, 100), 96);

            // Define background color
            graphics.BackgroundColor = Color.WhiteSmoke;

            // Init Create an instance of Imaging Pen class,  Brush class and mention its color.
            Pen pen = new Pen(Color.Blue);
            Brush brush = new SolidBrush(Color.YellowGreen);

            // Polygon Fill polygon and then Draw a polygon             
            graphics.FillPolygon(brush, new[] { new Point(2, 2), new Point(20, 20), new Point(20, 2) });
            graphics.DrawPolygon(pen, new[] { new Point(2, 2), new Point(20, 20), new Point(20, 2) });
            brush = new HatchBrush { HatchStyle = HatchStyle.Cross, BackgroundColor = Color.White, ForegroundColor = Color.Silver };

            // Fill ellipse  and  Draw an ellipse
            graphics.FillEllipse(brush, new Rectangle(25, 2, 20, 20));
            graphics.DrawEllipse(pen, new Rectangle(25, 2, 20, 20));

            // Arc Define pen style by setting DashStyle value, Set color of the pen
            pen.DashStyle = DashStyle.Dot;
            pen.Color = Color.Black;

            // Draw an Arc by calling DrawArc method and set CubicBezier
            graphics.DrawArc(pen, new Rectangle(50, 2, 20, 20), 0, 180);
            pen.DashStyle = DashStyle.Solid;
            pen.Color = Color.Red;

            // Draw an CubicBezier 
            graphics.DrawCubicBezier(pen, new Point(10, 25), new Point(20, 50), new Point(30, 50), new Point(40, 25));

            // Image  Create an Instance of Image class.
            using (Image image = Image.Load(dataDir + @"WaterMark.bmp"))
            {
                // Cast the instance of image class to RasterImage.
                RasterImage rasterImage = image as RasterImage;
                if (rasterImage != null)
                {
                    // Draw an image by calling DrawImage method and passing parameters rasterimage and point.
                    graphics.DrawImage(rasterImage, new Point(50, 50));
                }
            }

            // Line Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen.
            graphics.DrawLine(pen, new Point(2, 98), new Point(2, 50));

            // Pie Define settings of the brush object.
            brush = new SolidBrush(Color.Green);
            pen.Color = Color.DarkGoldenrod;

            // Fill pie by calling FillPie method and passing parameters brush and an instance of Imaging Rectangle class.
            graphics.FillPie(brush, new Rectangle(2, 38, 20, 20), 0, 45);

            // Draw pie by calling DrawPie method and passing parameters pen and an instance of Imaging Rectangle class.
            graphics.DrawPie(pen, new Rectangle(2, 38, 20, 20), 0, 45);
            pen.Color = Color.AliceBlue;

            // Polyline Draw Polyline by calling DrawPolyline method and passing parameters pen and points.
            graphics.DrawPolyline(pen, new[] { new Point(50, 40), new Point(75, 40), new Point(75, 45), new Point(50, 45) });

            // For having Strings Create an instance of Font class.
            Font font = new Font("Arial", 16);

            // Draw String by calling DrawString method and passing parameters string to display, color and X & Y coordinates.
            graphics.DrawString("Aspose", font, Color.Blue, 25, 75);

            // Call end recording of graphics object and save WMF image by calling Save method.
            using (WmfImage image = graphics.EndRecording())
            {
                image.Save(dataDir + "CreateWMFMetaFileImage.wmf");
            }
            // ExEnd:CreateWMFMetaFileImage
        }
コード例 #42
0
    internal override void Render(Graphics g)
    {
        UpdateGP();

        Brush brush;
        if (anchored)
            brush = new HatchBrush(HatchStyle.HorizontalBrick,Color.DarkGray,fillcolor);
        else
            brush = new SolidBrush(fillcolor);

        g.FillPath(brush,gp);
        g.DrawPath(Pens.Black,gp);

        brush.Dispose();

        Point cg = CG;
        g.FillRectangle(Brushes.Black,cg.X-30,cg.Y-30,61,61);
    }
コード例 #43
0
        public static void Run()
        {
            // ExStart:CreateEMFMetaFileImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // EmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it.
            EmfRecorderGraphics2D graphics = new EmfRecorderGraphics2D(new Rectangle(0, 0, 1000, 1000), new Size(1000, 1000), new Size(100, 100));
            {
                // Create an instance of Imaging Pen class and mention its color.
                Pen pen = new Pen(Color.Bisque);

                // Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen.
                graphics.DrawLine(pen, 1, 1, 50, 50);

                // Reset the Pen color Specify the end style of the line.
                pen = new Pen(Color.BlueViolet, 3);
                pen.EndCap = LineCap.Round;

                // Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen and end style of line.
                graphics.DrawLine(pen, 15, 5, 50, 60);

                // Specify the end style of the line.
                pen.EndCap = LineCap.Square;
                graphics.DrawLine(pen, 5, 10, 50, 10);
                pen.EndCap = LineCap.Flat;

                // Draw a line by calling DrawLine method and passing parameters.
                graphics.DrawLine(pen, new Point(5, 20), new Point(50, 20));

                // Create an instance of HatchBrush class to define rectanglurar brush with with different settings.
                HatchBrush hatchBrush = new HatchBrush
                {
                    BackgroundColor = Color.AliceBlue,
                    ForegroundColor = Color.Red,
                    HatchStyle = HatchStyle.Cross
                };

                // Draw a line by calling DrawLine method and passing parameters.
                pen = new Pen(hatchBrush, 7);
                graphics.DrawRectangle(pen, 50, 50, 20, 30);

                // Draw a line by calling DrawLine method and passing parameters with different mode.
                graphics.BackgroundMode = EmfBackgroundMode.OPAQUE;
                graphics.DrawLine(pen, 80, 50, 80, 80);

                // Draw a polygon by calling DrawPolygon method and passing parameters with line join setting/style.
                pen = new Pen(new SolidBrush(Color.Aqua), 3);
                pen.LineJoin = LineJoin.MiterClipped;
                graphics.DrawPolygon(pen, new[]
                {
                    new Point(10, 20),
                    new Point(12, 45),
                    new Point(22, 48),
                    new Point(48, 36),
                    new Point(30, 55)
                });

                // Draw a rectangle by calling DrawRectangle method.
                pen.LineJoin = LineJoin.Bevel;
                graphics.DrawRectangle(pen, 50, 10, 10, 5);
                pen.LineJoin = LineJoin.Round;
                graphics.DrawRectangle(pen, 65, 10, 10, 5);
                pen.LineJoin = LineJoin.Miter;
                graphics.DrawRectangle(pen, 80, 10, 10, 5);

                // Call EndRecording method to produce the final shape. EndRecording method will return the final shape as EmfImage. So create an instance of EmfImage class and initialize it with EmfImage returned by EndRecording method.
                using (EmfImage image = graphics.EndRecording())
                {
                    // Create an instance of PdfOptions class.
                    PdfOptions options = new PdfOptions();

                    // Create an instance of EmfRasterizationOptions class and define different settings.
                    EmfRasterizationOptions rasterizationOptions = new EmfRasterizationOptions();
                    rasterizationOptions.PageSize = image.Size;
                    options.VectorRasterizationOptions = rasterizationOptions;
                    string outPath = dataDir + "CreateEMFMetaFileImage_out.pdf";
                    image.Save(outPath, options);
                }
            }
            // ExEnd:CreateEMFMetaFileImage
        }
コード例 #44
0
ファイル: CaptchaProvider.cs プロジェクト: hoanghcmus/tomato
 /// <summary>
 /// Return the path of the captcha image
 /// </summary>
 /// <returns></returns>
 public string CreateCaptcha()
 {
     string[] fonts ={ "Counier New", "Comic Sans MS", "Times New Roman", "Tahoma" };
     const byte LENGTH = 5;
     // chiều dài chuỗi để lấy các kí tự sẽ sử dụng cho captcha
     const string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
     using (Bitmap bmp = new Bitmap(120, 35))
     {
         using (Graphics g = Graphics.FromImage(bmp))
         {
             // Tạo nền cho ảnh dạng sóng
             HatchBrush brush = new HatchBrush(HatchStyle.Percent80, Color.White, Color.Tan);
             g.FillRegion(brush, g.Clip);
             // Lưu chuỗi captcha trong quá trình tạo
             StringBuilder strCaptcha = new StringBuilder();
             Random rand = new Random();
             float locationX = 3;
             for (int i = 0; i < LENGTH; i++)
             {
                 // Lấy kí tự ngẫu nhiên từ mảng chars
                 SolidBrush brushes = new SolidBrush(GetRandomColor());
                 string str = chars[rand.Next(chars.Length)].ToString();
                 strCaptcha.Append(str);
                 // Tạo font với tên font ngẫu nhiên chọn từ mảng fonts
                 Font font = new Font(fonts[rand.Next(fonts.Length)], new Random().Next(14, 17), FontStyle.Bold | FontStyle.Italic);
                 // Lấy kích thước của kí tự
                 SizeF size = g.MeasureString(str, font);
                 // Vẽ kí tự đó ra ảnh tại vị trí tăng dần theo i, vị trí top ngẫu nhiên
                 g.DrawString(str, font,
                 brushes, locationX, rand.Next(2, 10));
                 font.Dispose();
                 //định location X
                 locationX += size.Width + i;
             }
             // Lưu captcha vào session
             Session[this.name] = strCaptcha.ToString();
             // Ghi ảnh trực tiếp ra luồng xuất theo định dạng gif
             //Response.ContentType = "image/GIF";4
             int numRandom = new Random().Next(1, 3000);
             string imgFile = "captcha" + numRandom + ".jpg";
             string directoryCaptcha = "~/UpLoads/tmp/";
             // Kiểm tra thư mục đã tồn tại
             if (!Directory.Exists(Server.MapPath(directoryCaptcha)))
             {
                 Directory.CreateDirectory(Server.MapPath(directoryCaptcha));
             }
             //lấy thông tin thư mục
             DirectoryInfo direcInfo = new DirectoryInfo(Server.MapPath(directoryCaptcha));
             foreach (FileInfo file in direcInfo.GetFiles(".jpg"))
             {
                 try
                 {
                     //Xóa tất cả các tập tin hình trong thư mục hiện tại
                     file.Delete();
                 }
                 catch { }
             }
             bmp.Save(Server.MapPath(directoryCaptcha + imgFile));
             return directoryCaptcha + imgFile;
         }
     }
 }
コード例 #45
0
ファイル: RandomImage.cs プロジェクト: thuyhk/ThuanThienVN
    private void GenerateImage()
    {
        Bitmap bitmap = new Bitmap
          (this.width, this.height, PixelFormat.Format32bppArgb);
        Graphics g = Graphics.FromImage(bitmap);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        Rectangle rect = new Rectangle(0, 0, this.width, this.height);
        HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti,
            Color.White, Color.White);
        g.FillRectangle(hatchBrush, rect);
        SizeF size;
        float fontSize = rect.Height + 1;
        Font font;

        do
        {
            fontSize--;
            font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
            size = g.MeasureString(this.text, font);
        } while (size.Width > rect.Width);
        StringFormat format = new StringFormat();
        format.Alignment = StringAlignment.Center;
        format.LineAlignment = StringAlignment.Center;
        GraphicsPath path = new GraphicsPath();
        //path.AddString(this.text, font.FontFamily, (int) font.Style,
        //    font.Size, rect, format);
        path.AddString(this.text, font.FontFamily, (int)font.Style, 30, rect, format);
        //float v = 4F;
        //PointF[] points =
        //  {
        //        new PointF(this.random.Next(rect.Width) / v, this.random.Next(
        //           rect.Height) / v),
        //        new PointF(rect.Width - this.random.Next(rect.Width) / v,
        //            this.random.Next(rect.Height) / v),
        //        new PointF(this.random.Next(rect.Width) / v,
        //            rect.Height - this.random.Next(rect.Height) / v),
        //        new PointF(rect.Width - this.random.Next(rect.Width) / v,
        //            rect.Height - this.random.Next(rect.Height) / v)
        //  };
        //Matrix matrix = new Matrix();
        //matrix.Translate(0F, 0F);
        //path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
        hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.CornflowerBlue);
        g.FillPath(hatchBrush, path);
        //int m = Math.Max(rect.Width, rect.Height);
        //for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
        //{
        //    int x = this.random.Next(rect.Width);
        //    int y = this.random.Next(rect.Height);
        //    int w = this.random.Next(m / 50);
        //    int h = this.random.Next(m / 50);
        //    g.FillEllipse(hatchBrush, x, y, w, h);
        //}
        font.Dispose();
        hatchBrush.Dispose();
        g.Dispose();
        this.image = bitmap;
    }
コード例 #46
0
    protected override void OnPaint(PaintEventArgs e)
    {
        Bitmap B = new Bitmap(Width, Height);
        Graphics G = Graphics.FromImage(B);

        G.SmoothingMode = SmoothingMode.HighQuality;

        double val = (double)_Value / _Maximum;
        int intValue = Convert.ToInt32(val * Width);
        G.Clear(BackColor);
        Color C1 = Color.FromArgb(174, 195, 30);
        Color C2 = Color.FromArgb(141, 153, 16);
        Rectangle R1 = new Rectangle(0, 0, Width - 1, Height - 1);
        Rectangle R2 = new Rectangle(0, 0, intValue - 1, Height - 1);
        Rectangle R3 = new Rectangle(0, 0, intValue - 1, Height - 2);
        GraphicsPath GP1 = Draw.RoundRect(R1, 1);
        GraphicsPath GP2 = Draw.RoundRect(R2, 2);
        GraphicsPath GP3 = Draw.RoundRect(R3, 1);
        LinearGradientBrush gB = new LinearGradientBrush(R1, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
        LinearGradientBrush g1 = new LinearGradientBrush(new Rectangle(2, 2, intValue - 1, Height - 2), C1, C2, 90);
        HatchBrush h1 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(50, C1), Color.FromArgb(25, C2));
        Pen P1 = new Pen(Color.Black);

        G.FillPath(gB, GP1);
        G.FillPath(g1, GP3);
        G.FillPath(h1, GP3);
        G.DrawPath(P1, GP1);
        G.DrawPath(new Pen(Color.FromArgb(150, 97, 94, 90)), GP2);
        G.DrawPath(P1, GP2);

        if (_ShowPercentage)
            G.DrawString(Convert.ToString(string.Concat(Value, "%")), Font, Brushes.White, R1, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });

        e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
        G.Dispose();
        B.Dispose();
    }