Beispiel #1
0
        private void Grafico_Reload(object sender, EventArgs e)
        {
            _Timer.Stop();

            //Dibuja los ejes
            _ejes.Reset();
            _ejes.AddLine(_pxMargen, _pxMargen, _pxMargen, this.Height - _pxMargen);
            _ejes.AddLine(_pxMargen, this.Height - _pxMargen, this.Width - _pxMargen, this.Height - _pxMargen);

            _valores.Reset();
            _valores.AddString(_MaxValueY.ToString(), System.Drawing.FontFamily.GenericSansSerif, (int)System.Drawing.FontStyle.Regular, (float)5, new System.Drawing.Point(0, _pxMargen), System.Drawing.StringFormat.GenericDefault);
            _valores.AddString(_MinValueY.ToString(), System.Drawing.FontFamily.GenericSansSerif, (int)System.Drawing.FontStyle.Regular, (float)5, new System.Drawing.Point(0, this.Height - _pxMargen), System.Drawing.StringFormat.GenericDefault);

            //Pepara la línea gráfica
            _Barras.Reset();
            Point[] _vertices = new Point[((this.Width - _pxMargen) / _pxAnchoTick) + 3];
            _vertices[0] = new Point(_pxMargen, this.Height - _pxMargen);
            _vertices[1] = _vertices[0];

            int lastX = _pxMargen;

            for (int i = 2; i < _vertices.Length - 2; i++)
            {
                lastX        = +_pxAnchoTick;
                _vertices[i] = new Point(lastX, this.Height - _pxMargen);
            }

            _vertices[_vertices.Length - 2] = new Point(this.Width, this.Height - _pxMargen);
            _vertices[_vertices.Length - 1] = _vertices[_vertices.Length - 2];

            _Timer.Start();
        }
Beispiel #2
0
        private void Form2_Paint(object sender, PaintEventArgs e)//画
        {
            String Str = "";

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            e.Graphics.FillRectangle(Brushes.White, e.Graphics.ClipBounds);

            //Draw Y 纵向轴绘制
            for (int i = 0; i <= this.ClientRectangle.Width / Unit_length; i++)
            {
                e.Graphics.DrawLine(TablePen, StartPrint + i * Unit_length, StartPrint, StartPrint + i * Unit_length, StartPrint + Y_Max);                                                                                                //画线

                gp.AddString((i * (Unit_length / DrawStep)).ToString(), this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(StartPrint + i * Unit_length - 7, this.ClientRectangle.Height - StartPrint + 4, 400, 50), null); //添加文字
            }
            //Draw X 横向轴绘制
            for (int i = 0; i <= this.ClientRectangle.Height / Unit_length; i++)
            {
                int k = 0;
                e.Graphics.DrawLine(TablePen, StartPrint, (i + 1) * Unit_length, this.ClientRectangle.Width, (i + 1) * Unit_length);//画线
                //    Str = ((16 - i) ).ToString();
                k = i % 2;
                //  Str = "0x" + (Str.Length == 1 ? Str + "0" : Str);
                if (k == 0)
                {
                    Str = "0";
                }
                else
                {
                    Str = "1";
                }
                // break;
                gp.AddString(Str, this.Font.FontFamily, (int)FontStyle.Regular, 14, new RectangleF(0, StartPrint + i * Unit_length - 8, 400, 50), null); //添加文字
            }
            e.Graphics.DrawPath(Pens.Black, gp);                                                                                                         //写文字
            if (DataList.Count - 1 >= (this.ClientRectangle.Width - StartPrint) / DrawStep)                                                              //如果数据量大于可容纳的数据量,即删除最左数据
            {
                DataList.RemoveRange(0, DataList.Count - (this.ClientRectangle.Width - StartPrint) / DrawStep - 1);
            }
            // = DataList.Count;
            for (int i = 0; i < DataList.Count - 1; i++)//绘制
            {
                e.Graphics.DrawLine(LinesPen, StartPrint + i * DrawStep, 17 * Unit_length - DataList[i] * 32, StartPrint + (i + 1) * DrawStep, 17 * Unit_length - DataList[i + 1] * 32);
            }
            for (int i = 0; i < DataList2.Count - 1; i++)//绘制
            {
                e.Graphics.DrawLine(LinesPen2, StartPrint + i * DrawStep, 15 * Unit_length - DataList2[i] * 32, StartPrint + (i + 1) * DrawStep, 15 * Unit_length - DataList2[i + 1] * 32);
            }
            for (int i = 0; i < DataList3.Count - 1; i++)//绘制
            {
                e.Graphics.DrawLine(LinesPen3, StartPrint + i * DrawStep, 13 * Unit_length - DataList3[i] * 32, StartPrint + (i + 1) * DrawStep, 13 * Unit_length - DataList3[i + 1] * 32);
            }
        }
Beispiel #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //現在時刻を取得しカスタム文字列で表示
            switch (mode)
            {
            case 1:
                dt = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                break;

            case 2:
                dt = DateTime.Now.ToString("yyyy/MM/dd \n") + DateTime.Now.ToString("HH:mm:ss");
                break;

            case 3:
                dt = DateTime.Now.ToString("HH:mm:ss");
                break;

            case 4:
                dt = DateTime.Now.ToString("HH:mm");
                break;
            }


            System.Drawing.Drawing2D.GraphicsPath path =
                new System.Drawing.Drawing2D.GraphicsPath();
            //文字のサイズは50
            path.AddString(dt, new FontFamily(font),
                           (int)FontStyle.Bold, size, new Point(0, 0),
                           StringFormat.GenericDefault);
            this.Region = new Region(path);

            /*if(Visible == false)
             *  Visible = true;*/
        }
Beispiel #4
0
        static public Rect Rect(string text, Emugen.Image.Primitive.Font efont, PointF position)
        {
            var frameSize    = 0.0;
            var frameSizeMax = 0.0;
            var rfontFrames  = new List <Emugen.Image.Primitive.Font.FontFrame>();

            foreach (var frame in efont.fontFrames)
            {
                frameSizeMax += frame.size / 2;
                rfontFrames.Insert(0, frame);
            }
            frameSize = frameSizeMax;

            // Todo : フォントフレームの幅分だけマージンの対応が必要
            var margin = (int)System.Math.Floor(frameSize + subMargin);

            var font         = CreateFont(efont.fontPath, efont.fontSize);
            var emFontFize   = (float)font.Height * font.FontFamily.GetEmHeight(font.Style) / font.FontFamily.GetLineSpacing(font.Style);
            var stringFormat = new System.Drawing.StringFormat();

            // 描画
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddString(text, font.FontFamily, (int)font.Style, emFontFize,
                           //path.AddString(text, font.FontFamily, (int)font.Style, (float)efont.fontSize,
                           new System.Drawing.PointF((float)(position.X), (float)(position.Y)),
                           stringFormat);

            var bound = path.GetBounds();
            //var result = new Rect(new Vector2D(bound.X - margin, bound.Y - margin), new Vector2D(bound.Width + margin * 2, bound.Height + margin * 2));
            var result = new Rect(new Vector2D(bound.X, bound.Y), new Vector2D(bound.Width, bound.Height));

            return(result);
        }
Beispiel #5
0
        public void init()
        {
            _bmpGameOver = new Bitmap(400, 128);

            System.Drawing.StringFormat strFmt = new StringFormat();
            strFmt.Alignment     = StringAlignment.Center;
            strFmt.LineAlignment = StringAlignment.Center;

            using (var g = System.Drawing.Graphics.FromImage(_bmpGameOver))
            {
                //g.Clear(Color.Black);

                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

                System.Drawing.Font font = new Font(_game.fontManager.titleFont, 20);

                path.AddString("GAME OVER", font.FontFamily, (int)font.Style, 40, new Rectangle(0, 0, _bmpGameOver.Width, _bmpGameOver.Height), strFmt);
                Brush borderBrush = Brushes.White;
                Pen   borderPen   = new Pen(borderBrush, 8);

                Brush brush = Brushes.Red;

                g.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                g.DrawPath(borderPen, path);
                g.FillPath(brush, path);
            }
        }
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="LabelPoint">Label placement</param>
        /// <param name="Offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="map">Map reference</param>
        public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, SharpMap.Map map)
        {
            System.Drawing.SizeF fontSize = g.MeasureString(text, font); //Calculate the size of the text
            LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y; //add label offset
            if (rotation != 0 && rotation != float.NaN)
            {
                g.TranslateTransform(LabelPoint.X, LabelPoint.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                    g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    g.DrawPath(halo, path);
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
                g.Transform = map.MapTransform;
            }
            else
            {
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                    g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null);
                if (halo != null)
                    g.DrawPath(halo, path);
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Beispiel #7
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            SolidBrush brushWhite = new SolidBrush(Color.White);
            //e.Graphics.FillRectangle(brushWhite, 0, 0,
            //this.ClientSize.Width, this.ClientSize.Height);

            FontFamily   fontFamily = new FontFamily("Arial");
            StringFormat strformat  = new StringFormat();
            string       szbuf      = txtbTrans.Text.ToString();

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(szbuf, fontFamily,
                           (int)FontStyle.Regular, 36.0f, new Point(10, 10), strformat);
            Pen pen = new Pen(Color.FromArgb(0, 0, 0), 6);

            pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
            e.Graphics.DrawPath(pen, path);
            SolidBrush brush = new SolidBrush(Color.FromArgb(255, 255, 0));

            e.Graphics.FillPath(brush, path);

            brushWhite.Dispose();
            fontFamily.Dispose();
            path.Dispose();
            pen.Dispose();
            brush.Dispose();
            e.Graphics.Dispose();
        }
Beispiel #8
0
        public void render(System.Drawing.Graphics g, string text, System.Drawing.Rectangle rect)
        {
            //string text = string.Format("SCORE: {0}", _scoreValue);
            var gp = new System.Drawing.Drawing2D.GraphicsPath();


            System.Drawing.FontFamily family = font;

            if (family == null)
            {
                family = System.Drawing.SystemFonts.DefaultFont.FontFamily;//
            }


            int fontStyle = (int)System.Drawing.FontStyle.Bold;

            gp.AddString(text, family, fontStyle, fontSize, rect, _strFmt);


            if (borderWidth > 0)
            {
                g.DrawPath(new Pen(borderColor, borderWidth), gp);
            }


            var brush = createBrush();

            g.FillPath(brush, gp);
        }
Beispiel #9
0
        static public void DrawText(Graphics graphics, Widget widget, bool usePath = false, StringFormat sf = null)
        {
            var str = string.IsNullOrEmpty(widget.Text) ? "..." : widget.Text;

            if (!usePath)
            {
                graphics.DrawString(
                    str,
                    widget.Font,
                    DictBrush[ColourClass.White],
                    widget.PaddedBounds,
                    new StringFormat()
                {
                    Alignment     = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center,
                }
                    );
            }
            else
            {
                using (var path = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    path.AddString(str, widget.Font.FontFamily, (int)FontStyle.Regular, widget.Font.Size, widget.Bounds, sf ?? WidgetButton.PathStringFormat);
                    //using (var spen = new Pen(Color.Black, 2F))  g.DrawPath(spen, path);
                    graphics.FillPath(Brushes.White, path);
                }
            }
        }
Beispiel #10
0
        private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Update the mouse path with the mouse information
            Point mouseDownLocation = new Point(e.X, e.Y);

            string eventString = null;

            switch (e.Button)
            {
            case MouseButtons.Left:
                eventString = "L";
                break;

            case MouseButtons.Right:
                eventString = "R";
                break;

            case MouseButtons.Middle:
                eventString = "M";
                break;

            case MouseButtons.XButton1:
                eventString = "X1";
                break;

            case MouseButtons.XButton2:
                eventString = "X2";
                break;

            case MouseButtons.None:
            default:
                break;
            }

            if (eventString != null)
            {
                mousePath.AddString(eventString, FontFamily.GenericSerif, (int)FontStyle.Bold, fontSize, mouseDownLocation, StringFormat.GenericDefault);
            }
            else
            {
                mousePath.AddLine(mouseDownLocation, mouseDownLocation);
            }
            panel1.Focus();
            panel1.Invalidate();
            count++;
        }
Beispiel #11
0
        private System.Drawing.Drawing2D.GraphicsPath GetSymbolOutlineByIndex(int symbolIndex)
        {
            System.Drawing.Drawing2D.GraphicsPath oOutline = new System.Drawing.Drawing2D.GraphicsPath();
            string sCharactor = new string(Convert.ToChar(symbolIndex), 1);

            oOutline.AddString(sCharactor, this._curFont.FontFamily, (int)FontStyle.Regular, this._fontSize, new Point(0, 0), StringFormat.GenericDefault);

            return(oOutline);
        }
 //根据验证字符串生成最终图象
 public void CreateImage(string str_ValidateCode)
 {
     //int int_ImageWidth = str_ValidateCode.Length * 13;
     //int width = int_ImageWidth;
     int int_ImageWidth = this.Width;
     int width = int_ImageWidth;
     int height = this.Height;
     string filePath = Server.MapPath(imgDir);
     Bitmap bgImg = (Bitmap)Bitmap.FromFile(GetRandomFile(filePath));
     Random newRandom = new Random();
     // 图高20px
     Bitmap theBitmap = new Bitmap(width, height);
     Graphics theGraphics = Graphics.FromImage(theBitmap);
     theGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
     theGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
     theGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     theGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
     // 白色背景
     //theGraphics.Clear(Color.White);
     theGraphics.DrawImage(bgImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, bgImg.Width, bgImg.Height), GraphicsUnit.Pixel);
     // 灰色边框
     //theGraphics.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, int_ImageWidth - 1, height - 1);
     //13pt的字体
     float fontSize = this.Height * 1.0f / 1.38f;
     float fontSpace = fontSize / 7f;
     Font theFont = new Font("Arial", fontSize);
     System.Drawing.Drawing2D.GraphicsPath gp = null;
     System.Drawing.Drawing2D.Matrix matrix;
     for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
     {
         string str_char = str_ValidateCode.Substring(int_index, 1);
         Brush newBrush = new SolidBrush(GetRandomColor());
         Point thePos = new Point((int)(int_index * (fontSize + fontSpace) + newRandom.Next(3)), 1 + newRandom.Next(3));
         gp = new System.Drawing.Drawing2D.GraphicsPath();
         gp.AddString(str_char, theFont.FontFamily, 0, fontSize, thePos, new StringFormat());
         matrix = new System.Drawing.Drawing2D.Matrix();
         int angle = GetRandomAngle();
         PointF centerPoint = new PointF(thePos.X + fontSize / 2, thePos.Y + fontSize / 2);
         matrix.RotateAt(angle, centerPoint);
         theGraphics.Transform = matrix;
         theGraphics.DrawPath(new Pen(Color.White, 2f), gp);
         //theGraphics.FillPath(new SolidBrush(Color.Black), gp);
         theGraphics.FillPath(new SolidBrush(GetRandomColor()), gp);
         theGraphics.ResetTransform();
     }
     if (gp != null) gp.Dispose();
     // 将生成的图片发回客户端
     MemoryStream ms = new MemoryStream();
     theBitmap.Save(ms, ImageFormat.Png);
     Response.ClearContent(); //需要输出图象信息 要修改HTTP头 
     Response.ContentType = "image/gif";
     Response.BinaryWrite(ms.ToArray());
     theGraphics.Dispose();
     theBitmap.Dispose();
     Response.End();
 }
Beispiel #13
0
        //文字列の白抜き描画
        /// <summary>
        ///		文字列を白抜きで描画する
        /// </summary>
        /// <param name="sString">描画する文字列</param>
        /// <param name="x">文字列の左上端のX座標</param>
        /// <param name="y">文字列の左上端のY座標</param>
        public void DrawStringWhiteBackground(string sString, int x, int y)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString(sString, new FontFamily(fFont.Name), 0, fFont.Size, new Point(x, y), StringFormat.GenericDefault);

            //白抜きにする
            pTarget.Graphics.FillPath(Brushes.White, gp);

            //描画
            pTarget.Graphics.DrawPath(pPen, gp);
        }
Beispiel #14
0
 private void draw(object sender, EventArgs e)
 {
     using (Graphics graphics = Graphics.FromImage(bitmap))
     {
         graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         graphics.FillRectangle(new SolidBrush(color), new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
         System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         graphicsPath.AddString(textBox2.Text, font.FontFamily, (int)FontStyle.Regular, (int)numericUpDown4.Value, new Point((int)numericUpDown1.Value, (int)numericUpDown2.Value), StringFormat.GenericDefault);
         graphics.FillPath(Brushes.White, graphicsPath);
         graphics.DrawPath(new Pen(Color.Black, (int)numericUpDown3.Value), graphicsPath);
     }
     pictureBox1.Image = bitmap;
 }
Beispiel #15
0
        public static void DrawText(Font font, StringFormat sf, System.Drawing.Drawing2D.GraphicsPath path, StringBuilder sb, bool isItalic, float left, float top, ref bool newLine, float addX, float leftMargin)
        {
            PointF next = new PointF(left, top);

            if (path.PointCount > 0)
            {
                int k = 0;
                for (int i = path.PathPoints.Length - 1; i >= 0; i--)
                {
                    if (path.PathPoints[i].X > next.X)
                    {
                        next.X = path.PathPoints[i].X;
                    }
                    k++;
                    if (k > 10)
                    {
                        break;
                    }
                }
            }

            next.X += addX;
            if (newLine)
            {
                next.X  = leftMargin;
                newLine = false;
            }

            if (isItalic)
            {
                path.AddString(sb.ToString(), font.FontFamily, (int)System.Drawing.FontStyle.Italic, font.Size, next, sf);
            }
            else
            {
                path.AddString(sb.ToString(), font.FontFamily, 0, font.Size, next, sf);
            }

            sb.Length = 0;
        }
Beispiel #16
0
        private void Alerta_Paint(object sender, PaintEventArgs e)
        {
            //Brush pincel = new SolidBrush(this.ForeColor);
            //Brush pincelSombra = new TextureBrush(Image.FromFile("recursos/fondo ojos.png"));
            //Font fuenteSombra = new Font(this.Font.FontFamily, (float)(this.Font.Size));
            ImageAnimator.UpdateFrames(this.imagen);
            //Font fuente = this.Font;
            //SizeF tamañoTexto = new SizeF(Width, Height);
            string[] textos        = _texto.Split(new char[] { '\n' });
            float    posY          = this.Padding.Top;
            float    proporcionDpi = e.Graphics.DpiY / 72;

            // using (Bitmap bmp = new Bitmap(this.imagen.Width, this.imagen.Height)) {
            //    using (Graphics gr = Graphics.FromImage(bmp)) {
            //       gr.DrawImage(this.imagen, _izquierda, _arriba, _ancho, _alto);
            //    }
            //    bmp.MakeTransparent(Color.Black);
            e.Graphics.DrawImage(this.imagen, _izquierda, _arriba, _ancho, _alto);
            // }
            foreach (string texto in textos)
            {
                SizeF        dimensionTexto = e.Graphics.MeasureString(texto, _fuente);
                StringFormat sf             = new StringFormat();
                if (texto[0] != '#')
                {
                    //SizeF dimensionTexto = e.Graphics.MeasureString(texto, _fuente);
                    int x = (int)((Width / 2) - (dimensionTexto.Width / 2));
                    int y = (int)posY;

                    e.Graphics.DrawString(texto, _fuenteSombra, _pincelSombra, x + this.Padding.Left - 1, y - 1);
                    e.Graphics.DrawString(texto, _fuenteSombra, _pincelSombra, x + this.Padding.Left + 1, y + 1);
                    System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                    Pen borde = new Pen(Color.FromArgb(0, 0, 0), 3);
                    borde.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;

                    gp.AddString(texto, _fuente.FontFamily, (int)_fuente.Style, _fuente.Size * proporcionDpi, new Point(x + this.Padding.Left, y), sf);
                    //e.Graphics.ScaleTransform(1.3f, 1.35f);
                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    e.Graphics.DrawPath(borde, gp);
                    e.Graphics.FillPath(_pincel, gp);
                    //e.Graphics.DrawString(texto, _fuente, _pincel, x + this.Padding.Left, y);
                    posY += dimensionTexto.Height + separacion;
                }
                else
                {
                    posY += procesarParámetro(texto, dimensionTexto.Height);
                }
            }
        }
Beispiel #17
0
        static public void Do(string text, Emugen.Image.Primitive.Font efont, Graphics graphics, PointF position)
        {
            var frameSize    = 0.0;
            var frameSizeMax = 0.0;
            var rfontFrames  = new List <Emugen.Image.Primitive.Font.FontFrame>();

            foreach (var frame in efont.fontFrames)
            {
                frameSizeMax += frame.size;
                rfontFrames.Insert(0, frame);
            }
            frameSize = frameSizeMax;

            // Todo : フォントフレームの幅分だけマージンの対応が必要
            //var margin = (int)System.Math.Floor(frameSize + subMargin);
            //var margin = 0;

            var font         = CreateFont(efont.fontPath, efont.fontSize);
            var emFontFize   = (float)font.Height * font.FontFamily.GetEmHeight(font.Style) / font.FontFamily.GetLineSpacing(font.Style);
            var stringFormat = new System.Drawing.StringFormat();

            // 描画
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddString(text, font.FontFamily, (int)font.Style, emFontFize,
                           new System.Drawing.PointF((float)(position.X), (float)(position.Y)),
                           stringFormat);

            {
                var g = graphics;

                var brush = default(System.Drawing.SolidBrush);
                brush           = new System.Drawing.SolidBrush(efont.bodyColor.ToSystemDrawingColor());
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                frameSize = frameSizeMax;

                foreach (var frame in rfontFrames)
                {
                    var pen = new System.Drawing.Pen(frame.color.ToSystemDrawingColor(), (float)frameSize);
                    g.DrawPath(pen, path);

                    frameSize -= frame.size;
                }

                g.FillPath(brush, path);
            }
        }
Beispiel #18
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawing = false;

            pictureBox1.Refresh();

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, fontSize, theRectangle, new StringFormat());
            formGraphics.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
            formGraphics.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);

            labelState.Text = e.Location.X.ToString() + " , " + e.Location.Y.ToString();

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Wallpaper.BurnNewWallpaper(Wallpaper.wallpaperFile.FullName), SPIF_UPDATEINIFILE);
        }
Beispiel #19
0
        //文字が読みずらいので、TextShadowぽいのを作る
        //see http://www.r-nakai.com/archives/280
        private void Button_Paint(object sender, PaintEventArgs e)
        {
            Button btn = (Button)sender;

            //アンチエリアス
            System.Drawing.Drawing2D.SmoothingMode initialMode
                = e.Graphics.SmoothingMode;
            e.Graphics.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //レンダリング品質
            System.Drawing.Drawing2D.CompositingQuality initialQuality
                = e.Graphics.CompositingQuality;
            e.Graphics.CompositingQuality
                = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

            string str = (String)btn.Tag;

            SizeF size = e.Graphics.MeasureString(str, btn.Font);
            int   x    = (int)((btn.Width / 2) - (size.Width / 1.5));
            int   y    = btn.Height - btn.Font.Height - 10;

            System.Drawing.Drawing2D.GraphicsPath gp =
                new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddString(str, btn.Font.FontFamily
                         , (int)FontStyle.Regular
                         , btn.Font.Size + 10
                         , new Point(x, y), StringFormat.GenericDefault);

            //パスの線分を描画
            Pen drawPen = new Pen(btn.BackColor, 3.0F);

            e.Graphics.DrawPath(drawPen, gp);

            //塗る
            Brush fillBrush = new SolidBrush(btn.ForeColor);

            e.Graphics.FillPath(fillBrush, gp);

            drawPen.Dispose();
            fillBrush.Dispose();

            //念のため元に戻しておきます
            e.Graphics.SmoothingMode      = initialMode;
            e.Graphics.CompositingQuality = initialQuality;
        }
Beispiel #20
0
        public void DrawRect(int[] data)
        {
            Debug.WriteLine(data);

            Point min = scaledPoint(new Point(data[0], data[1]));
            Point max = scaledPoint(new Point(data[2], data[3]));

            Debug.WriteLine(min);
            Debug.WriteLine(max);

            Rectangle rect = new Rectangle(min.X, min.Y, max.X - min.X, max.Y - min.Y);

            vehiclePath.Reset();
            vehiclePath.AddRectangle(rect);
            speedPath.AddString(data[4].ToString() + " kmh", System.Drawing.FontFamily.GenericSansSerif, 0, 18, new Point(min.X, min.Y - 18), StringFormat.GenericDefault);

            pictureBox.Invalidate();
        }
Beispiel #21
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            _theGame.Draw(e.Graphics, _interp);

            // draw fps
            var path = new System.Drawing.Drawing2D.GraphicsPath();
            Pen p = new Pen(Color.Black, 2.0f);
            path.AddString(String.Format("FPS: {0}", _fpsCalc.Fps),
                           FontFamily.GenericSansSerif, 0, 24f,
                           Point.Empty, StringFormat.GenericTypographic);
            e.Graphics.DrawPath(p, path);
            e.Graphics.FillPath(Brushes.White, path);
            p.Dispose();
            path.Dispose();

            _fpsCalc.DrawFrame(); // used for calculating FPS
        }
Beispiel #22
0
        public static Image writeNG(Image img)
        {
            img = new Bitmap(img, 64, 64);
            var g = Graphics.FromImage(img);

            //var font = new Font("MS UI Gothic", 25, FontStyle.Regular);
            g.DrawLine(new Pen(Color.Red, 3), 0, 0, img.Width, img.Height);
            g.DrawLine(new Pen(Color.Red, 3), img.Width, 0, 0, img.Height);
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddString("NG", FontFamily.GenericSansSerif, 0, 30, new PointF(3, 11), StringFormat.GenericDefault);
            g.FillPath(new SolidBrush(Color.Red), path);
            g.DrawPath(new Pen(Color.FromArgb(10, 10, 10)), path);
            g.Flush();

            //if (ret != DialogResult.OK) return null;
            return(img);
        }
Beispiel #23
0
        private void set_jimaku()
        {
            System.Drawing.Drawing2D.GraphicsPath path =
                new System.Drawing.Drawing2D.GraphicsPath();

            int style = 0;

            style += (text.Font.Bold) ? (int)FontStyle.Bold : (int)FontStyle.Regular;
            style += (text.Font.Italic) ? (int)FontStyle.Italic : (int)FontStyle.Regular;
            style += (text.Font.Underline) ? (int)FontStyle.Underline : (int)FontStyle.Regular;
            style += (text.Font.Strikeout) ? (int)FontStyle.Strikeout : (int)FontStyle.Regular;
            path.AddString(text.Text, text.Font.FontFamily,
                           style,
                           (float)(text.Font.SizeInPoints / 0.75), new Point(0, 0),
                           StringFormat.GenericDefault);
            myForm.Region    = new Region(path);
            myForm.BackColor = text.ForeColor;
            path.Dispose();
        }
Beispiel #24
0
        private Size MeasureText(Graphics graphics, string text, Font font)
        {
            var sz = TextRenderer.MeasureText(graphics, text, this.Font, new Size(0, 0), tf);
            return sz;

            var bounds = new RectangleF();
            using (var textPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                textPath.AddString(
                    text,
                    font.FontFamily,
                    (int)font.Style,
                    font.Size,
                    new PointF(0, 0),
                    StringFormat.GenericTypographic);
                bounds = textPath.GetBounds();
            }
            return new Size((int)bounds.Width, (int)bounds.Height);
        }
Beispiel #25
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            _theGame.Draw(e.Graphics, _interp);

            // draw fps
            var path = new System.Drawing.Drawing2D.GraphicsPath();
            Pen p    = new Pen(Color.Black, 2.0f);

            path.AddString(String.Format("FPS: {0}", _fpsCalc.Fps),
                           FontFamily.GenericSansSerif, 0, 24f,
                           Point.Empty, StringFormat.GenericTypographic);
            e.Graphics.DrawPath(p, path);
            e.Graphics.FillPath(Brushes.White, path);
            p.Dispose();
            path.Dispose();

            _fpsCalc.DrawFrame(); // used for calculating FPS
        }
Beispiel #26
0
            public ViewGeo(EvalGraphControl con)
            {
                plyMax = Math.Max((Math.Max(con.evaldata.maxIndex, con.evaldata.selectedIndex) + 9) / 10 * 10, 50);
                var plyMaxLen = $"{plyMax}".Length;

                hScrollValue  = con.HorizontalScroll.Value;
                scoreFontSize = Math.Max(Math.Min(con.Width / 16f, con.Height / 16f), 1f);
                lineWidthMul  = Math.Max(Math.Min(con.Width, con.Height) / 512f, 1f);
                scaleLineLen  = 6 * lineWidthMul;
                scaleTextPad  = 8 * lineWidthMul;
                RectangleF bounds;

                using (var path = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    using (var font = new FontFamily(con.fontFamilyName))
                        path.AddString(
                            "+9999",
                            font,
                            (int)FontStyle.Regular,
                            scoreFontSize,
                            new PointF(0f, 0f),
                            new StringFormat()
                        {
                            Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near
                        }
                            );
                    bounds = path.GetBounds();
                    lPad   = 4 + (int)(-1.0f * bounds.Left + scaleTextPad);
                    rPad   = 4 + (int)(-0.1f * plyMaxLen * bounds.Left);
                    uPad   = 4 + (int)(+0.5f * bounds.Bottom);
                    bPad   = 4 + (int)(+1.0f * bounds.Bottom + scaleTextPad);
                }
                xlen           = con.evalGraphPictureBox.Width - lPad - rPad;
                ymul           = (con.evalGraphPictureBox.Height - uPad - bPad) * 0.5f;
                yadd           = uPad + ymul;
                graphBodyWidth = con.Width - lPad - rPad;
                plyWidth       = Math.Max(graphBodyWidth / plyMax, 4f);
                plyFontSize    = Math.Max(Math.Min(scoreFontSize * plyWidth * -80f / (plyMaxLen * bounds.Left), scoreFontSize), 1f);
                scoreRound     = Math.Max(Math.Min(con.Height * 0.01f, plyWidth * 0.5f), 3f);
                scoreLineWidth = Math.Max(scoreRound * 0.5f, 1f);
                boxWidth       = Math.Max((int)(lPad + rPad + plyMax * plyWidth), con.Width);
            }
Beispiel #27
0
        private void DrawCharactorsOutLines(ref Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsPath oOutline = new System.Drawing.Drawing2D.GraphicsPath();
            int iSymbolIndex = 0;

            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    string sCharactor = new string(Convert.ToChar(iSymbolIndex++), 1);
                    oOutline = new System.Drawing.Drawing2D.GraphicsPath();
                    oOutline.AddString(sCharactor, this._curFont.FontFamily, (int)FontStyle.Regular, this._fontSize - 7, new Point(j * this._fontSize, i * this._fontSize), StringFormat.GenericDefault);
                    g.FillPath(new SolidBrush(Color.Black), oOutline);
                    oOutline.Dispose();
                    //g.DrawString(sCharactor, this._curFont, new SolidBrush(Color.Black), new RectangleF(j * this._fontSize , i * this._fontSize, this._fontSize, this._fontSize), StringFormat.GenericTypographic);
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Gets the default plot symbol size for all graphics in this graph, using the provided property context.
        /// </summary>
        /// <param name="context">The property context.</param>
        /// <returns>Default plot symbol size in points (1/72 inch).</returns>
        public static double GetDefaultSymbolSize(Altaxo.Main.Properties.IReadOnlyPropertyBag context)
        {
            double result = 1;

            if (null != context)
            {
                var font = context.GetValue(PropertyKeyDefaultFont);
                using (var path = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    path.AddString("x", Gdi.GdiFontManager.ToGdi(font.Font).FontFamily, (int)font.Style, (float)font.Size, new System.Drawing.PointF(0, 0), System.Drawing.StringFormat.GenericTypographic);
                    var bounds = path.GetBounds();

                    if (bounds.Height > 0)
                    {
                        result = Calc.Rounding.RoundToNumberOfSignificantDigits(bounds.Height, 2, MidpointRounding.ToEven);
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="LabelPoint">Label placement</param>
        /// <param name="Offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="map">Map reference</param>
        public static void DrawLabel(System.Drawing.Graphics g, System.Drawing.PointF LabelPoint, System.Drawing.PointF Offset, System.Drawing.Font font, System.Drawing.Color forecolor, System.Drawing.Brush backcolor, System.Drawing.Pen halo, float rotation, string text, SharpMap.Map map)
        {
            System.Drawing.SizeF fontSize = g.MeasureString(text, font);    //Calculate the size of the text
            LabelPoint.X += Offset.X; LabelPoint.Y += Offset.Y;             //add label offset
            if (rotation != 0 && !float.IsNaN(rotation))
            {
                g.TranslateTransform(LabelPoint.X, LabelPoint.Y);
                g.RotateTransform(rotation);
                g.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                {
                    g.FillRectangle(backcolor, 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
                g.Transform = map.MapTransform;
            }
            else
            {
                if (backcolor != null && backcolor != System.Drawing.Brushes.Transparent)
                {
                    g.FillRectangle(backcolor, LabelPoint.X, LabelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);
                }

                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

                path.AddString(text, font.FontFamily, (int)font.Style, font.Size, LabelPoint, null);
                if (halo != null)
                {
                    g.DrawPath(halo, path);
                }
                g.FillPath(new System.Drawing.SolidBrush(forecolor), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Beispiel #30
0
		void TextEvent(object sender, EventArgs e)
		{
			thumbBox.Image = resetImage();
			
			if (text.Text == "") {
				//thumbBox.Image = img;
				return;
			}
			//if (sizeList.Value == 0) return;
			//thumbBox.Image = new Bitmap(img);
			
			
			var g = Graphics.FromImage(thumbBox.Image);
			var font = new Font("MS UI Gothic", (int)sizeList.Value, FontStyle.Regular);
			var path = new System.Drawing.Drawing2D.GraphicsPath();
			path.AddString(text.Text, FontFamily.GenericSansSerif, 0, (float)sizeList.Value, new PointF((float)xList.Value, (float)yList.Value), StringFormat.GenericDefault);
			
			g.FillPath(new SolidBrush(Color.White), path);
			g.DrawPath(new Pen(Color.FromArgb(50, 50, 50)), path);
			g.Flush();
		}
Beispiel #31
0
        private Size MeasureText(Graphics graphics, string text, Font font)
        {
            var sz = TextRenderer.MeasureText(graphics, text, this.Font, new Size(0, 0), tf);

            return(sz);

            var bounds = new RectangleF();

            using (var textPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                textPath.AddString(
                    text,
                    font.FontFamily,
                    (int)font.Style,
                    font.Size,
                    new PointF(0, 0),
                    StringFormat.GenericTypographic);
                bounds = textPath.GetBounds();
            }
            return(new Size((int)bounds.Width, (int)bounds.Height));
        }
Beispiel #32
0
        private void ImageYarat()
        {
            this.familyName = System.Drawing.FontFamily.GenericSerif.Name;

            // 32bit bmp yaratalim
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(this.m_width, this.m_height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            // cizim icin bir graphics nesnesi yaratalim.
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            System.Drawing.Rectangle rec = new System.Drawing.Rectangle(0, 0, this.m_width, this.m_height);
            // Resimde arka alani dolduralim
            System.Drawing.Drawing2D.HatchBrush hb = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.White);
            g.FillRectangle(hb, rec);
            System.Drawing.Font font = new System.Drawing.Font(this.familyName, this.FontSize, System.Drawing.FontStyle.Bold);
            // textin formatini belirleyelim
            System.Drawing.StringFormat format = new System.Drawing.StringFormat();
            format.Alignment     = System.Drawing.StringAlignment.Center;
            format.LineAlignment = System.Drawing.StringAlignment.Center;
            // bir path belirleyip, texte random olarak aci verelim
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(this.m_text, font.FontFamily, (int)font.Style, font.Size, rec, format);
            float v = 4;

            System.Drawing.PointF[]         p      = { new System.Drawing.PointF(this.random.Next(rec.Width) / v, this.random.Next(rec.Height) / v), new System.Drawing.PointF(rec.Width - this.random.Next(rec.Width) / v, this.random.Next(rec.Height) / v), new System.Drawing.PointF(this.random.Next(rec.Width) / v, rec.Height - this.random.Next(rec.Height) / v), new System.Drawing.PointF(rec.Width - this.random.Next(rec.Width) / v, rec.Height - this.random.Next(rec.Height) / v) };
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(0f, 0f);
            path.Warp(p, rec, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0);
            hb = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.Blue);
            g.FillPath(hb, path);
            for (int i = 0; i <= (int)(rec.Width * rec.Height / 30) - 1; i++)
            {
                int x = this.random.Next(rec.Width);
                int y = this.random.Next(rec.Height);
                int w = this.random.Next(rec.Width / 50);
                int h = this.random.Next(rec.Width / 40);
                g.FillEllipse(hb, x, y, w, h);
            }
            this.m_image = bitmap;
        }
Beispiel #33
0
        /// <summary>
        /// 文字列をオフスクリーンに書き込みます。
        /// </summary>
        /// <param name="text">書き込む文字列</param>
        /// <param name="font"><paramref name="text"/> のフォント</param>
        /// <param name="color"><paramref name="text"/> の色</param>
        /// <param name="outlineColor"><paramref name="text"/> の縁取り色</param>
        /// <param name="rectangle"><paramref name="text"/> の書き込み位置及び範囲</param>
        internal void DrawText(string text, System.Drawing.Font font, System.Drawing.Brush color, System.Drawing.Pen outlineColor, System.Drawing.RectangleF rectangle)
        {
            using (var g = System.Drawing.Graphics.FromImage(OffScreen)) {
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                if (outlineColor == null)
                {
                    g.FillRectangle(System.Drawing.Brushes.Transparent, rectangle);
                    g.DrawString(text, font, color, rectangle);
                }
                else
                {
                    using (var gp = new System.Drawing.Drawing2D.GraphicsPath()) {
                        var sizeInPixels = font.SizeInPoints * g.DpiY / 72;
                        gp.AddString(text, font.FontFamily, (int)font.Style, sizeInPixels, rectangle, null);
                        g.DrawPath(outlineColor, gp);
                        g.FillPath(color, gp);
                    }
                }
            }
        }
Beispiel #34
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            labelState.Text = e.Location.X.ToString() + " , " + e.Location.Y.ToString();

            if (isDrawing)
            {
                pictureBox1.Refresh();
                Color newColor = Color.FromArgb(125, Color.Gray);

                Control control = (Control)sender;
                formGraphics = control.CreateGraphics();
                formGraphics.FillRectangle(new SolidBrush(newColor), theRectangle);
                formGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                theRectangle.X             = startpoint.X;
                theRectangle.Y             = startpoint.Y;
                theRectangle.Height        = e.Y - startpoint.Y;
                theRectangle.Width         = e.X - startpoint.X;

                fontSize = 96f;
                SizeF stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));

                if (theRectangle.Width > 15 && theRectangle.Height > 15)
                {
                    while (stringSize.Width > theRectangle.Width || stringSize.Height > theRectangle.Height)
                    {
                        stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));
                        fontSize  -= 0.05f;
                    }

                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, fontSize, theRectangle, new StringFormat());
                    formGraphics.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
                    formGraphics.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);

                    Settings.ChangeSetting(Settings.settings.fontSize, fontSize.ToString());
                    Wallpaper.fontSize = this.fontSize;
                }
            }
        }
        /// <summary>
        /// Bakes the current time on the original wallpaper and returns the path of the baked wallpaper.
        /// </summary>
        /// <param name="originalWallpaperPath">The full path of the original wallpaper.</param>
        /// <returns></returns>
        public static string BurnNewWallpaper(string originalWallpaperPath)
        {
            Image wallpaper = Image.FromFile(originalWallpaperPath);
            Bitmap bufferBtmp = new Bitmap(wallpaper);
            Graphics wallpaperGraph = Graphics.FromImage(bufferBtmp);
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            wallpaperGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            wallpaperGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
            path.FillMode = System.Drawing.Drawing2D.FillMode.Winding;

            path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, (float)(fontSize * Convert.ToDouble(wallpaper.Width) / Convert.ToDouble(pictureBoxRectangle.Width)), CalculateTheRelativePoint(), new StringFormat());
            wallpaperGraph.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
            wallpaperGraph.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);
            BurntWallpaperPath = Settings.rootDirectory + "\\wallpaper.png";

            bufferBtmp.Save(BurntWallpaperPath);
            bufferBtmp.Dispose();
            wallpaper.Dispose();
            wallpaperGraph.Dispose();

            return BurntWallpaperPath;
        }
Beispiel #36
0
        public Caption Render(string message, Position position, string fontName, float fontSize, bool isBold, bool isItalic, Color fontColor, Color bgColor, float bgBorder)
        {
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                float padding = bgBorder * g.DpiX / 72;
                float x = padding;
                float y = padding;

                int fontStyle = (int)System.Drawing.FontStyle.Regular;
                if (isBold) fontStyle |= (int)System.Drawing.FontStyle.Bold;
                if (isItalic) fontStyle |= (int)System.Drawing.FontStyle.Italic;

                Font font = new Font(fontName, fontSize);
                Brush brush = new SolidBrush(fontColor);
                Brush bbrush = new SolidBrush(bgColor);
                Pen pen = new Pen(bbrush, padding);

                pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                // Get Render Bounds
                RectangleF rect;
                using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(padding, padding), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);

                    rect = gp.GetBounds();
                }

                // Render
                if (position == K4WDisclaimer.Position.Bottom)
                {
                    y = bitmap.Height - rect.Height - rect.Y - padding;
                }
                using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
                {

                    gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(x, y), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);
                    g.FillPath(bbrush, gp);
                    g.DrawPath(pen, gp);
                    g.FillPath(brush, gp);
                }

                brush.Dispose();
                bbrush.Dispose();
                pen.Dispose();
                font.Dispose();
            }
            return this;
        }
Beispiel #37
0
        private void DrawCharactorsOutLines(ref Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsPath oOutline = new System.Drawing.Drawing2D.GraphicsPath();
            int iSymbolIndex = 0;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    string sCharactor = new string(Convert.ToChar(iSymbolIndex++), 1);
                    oOutline = new System.Drawing.Drawing2D.GraphicsPath();
                    oOutline.AddString(sCharactor, this._curFont.FontFamily, (int)FontStyle.Regular, this._fontSize - 7, new Point(j * this._fontSize, i * this._fontSize), StringFormat.GenericDefault);
                    g.FillPath(new SolidBrush(Color.Black), oOutline);
                    oOutline.Dispose();
                    //g.DrawString(sCharactor, this._curFont, new SolidBrush(Color.Black), new RectangleF(j * this._fontSize , i * this._fontSize, this._fontSize, this._fontSize), StringFormat.GenericTypographic);
                }
            }
        }
Beispiel #38
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (listBox1.SelectedIndex)
            {
            case 0:
                {
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.
                Drawing2D.LineCap.Round, System.Drawing.Drawing2D.DashCap.Round);
                    break;
                }
            case 1:
                {
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.ArrowAnchor, System.Drawing.
                Drawing2D.LineCap.ArrowAnchor, System.Drawing.Drawing2D.DashCap.Round);
                    break;
                }
            case 2:
                {
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Square, System.Drawing.
                Drawing2D.LineCap.Square, System.Drawing.Drawing2D.DashCap.Round);
                    break;
                }
            case 3:
                {
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Triangle, System.Drawing.
                Drawing2D.LineCap.Triangle, System.Drawing.Drawing2D.DashCap.Round);
                    break;
                }
            case 4:
                {
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.DiamondAnchor, System.Drawing.
                Drawing2D.LineCap.DiamondAnchor, System.Drawing.Drawing2D.DashCap.Round);

                    break;
                }
            case 5:
                {
                    System.Drawing.Drawing2D.GraphicsPath hPath = new System.Drawing.Drawing2D.GraphicsPath();

                    Rectangle rect = new Rectangle(0,0,(int)MyPen.Width,(int)MyPen.Width);
                    hPath.AddString("O", FontFamily.GenericSansSerif, (int)FontStyle.Italic, (float)0.05, rect, StringFormat.GenericDefault);

                    System.Drawing.Drawing2D.CustomLineCap HookCap = new System.Drawing.Drawing2D.CustomLineCap(null, hPath);

                    HookCap.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round);

                    MyPen.CustomStartCap = HookCap;
                    MyPen.CustomEndCap = HookCap;
                    MyPen.SetLineCap(System.Drawing.Drawing2D.LineCap.Custom, System.Drawing.
                Drawing2D.LineCap.Custom, System.Drawing.Drawing2D.DashCap.Round);

                    break;
                }
            }
        }
Beispiel #39
0
        private byte[] GenerateCaptchaImage(string text, int width, int height)
        {
            Random random = new Random(int.Parse(Guid.NewGuid().ToString().Substring(0, 8), System.Globalization.NumberStyles.HexNumber));

            System.Drawing.Font font;
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp);
            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
            System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallConfetti, System.Drawing.Color.LightGray, System.Drawing.Color.White);
            graphics.FillRectangle(brush, rect);

            float emSize = rect.Height + 1;

            do {
                emSize--;
                font = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, emSize, System.Drawing.FontStyle.Bold);
            } while (graphics.MeasureString(text, font).Width > rect.Width);

            System.Drawing.StringFormat format = new System.Drawing.StringFormat {
                Alignment = System.Drawing.StringAlignment.Center,
                LineAlignment = System.Drawing.StringAlignment.Center
            };

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(text, font.FontFamily, (int)font.Style, 75f, rect, format);
            float num2 = 4f;
            System.Drawing.PointF[] destPoints = new System.Drawing.PointF[] { new System.Drawing.PointF(((float)random.Next(rect.Width)) / num2, ((float)random.Next(rect.Height)) / num2), new System.Drawing.PointF(rect.Width - (((float)random.Next(rect.Width)) / num2), ((float)random.Next(rect.Height)) / num2), new System.Drawing.PointF(((float)random.Next(rect.Width)) / num2, rect.Height - (((float)random.Next(rect.Height)) / num2)), new System.Drawing.PointF(rect.Width - (((float)random.Next(rect.Width)) / num2), rect.Height - (((float)random.Next(rect.Height)) / num2)) };
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(0f, 0f);
            path.Warp(destPoints, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0f);
            brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent10, System.Drawing.Color.Black, System.Drawing.Color.SkyBlue);
            graphics.FillPath(brush, path);

            int num3 = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < ((int)(((float)(rect.Width * rect.Height)) / 30f)); i++) {
                int x = random.Next(rect.Width);
                int y = random.Next(rect.Height);
                int w = random.Next(num3 / 50);
                int h = random.Next(num3 / 50);
                graphics.FillEllipse(brush, x, y, w, h);
            }
            font.Dispose();
            brush.Dispose();
            graphics.Dispose();

            System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
            bmp.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            byte[] imageContent = new Byte[imageStream.Length];
            imageStream.Position = 0;
            imageStream.Read(imageContent, 0, (int)imageStream.Length);
            return imageContent;
        }
        public ActionResult UnderLine()
        {
            string sVirtualPath = @"/Content/File/UnderLine/";

            //web请求
            HttpServerUtility httpServerUtility = System.Web.HttpContext.Current.Server;
            if (!Directory.Exists(httpServerUtility.MapPath(sVirtualPath)))
            {
                //按虚拟路径创建所有目录和子目录
                Directory.CreateDirectory(@httpServerUtility.MapPath(sVirtualPath));
            }

            string index = "1";
            string reIndex = Request["index"];
            if (!string.IsNullOrEmpty(reIndex))
            {
                int n;
                index = int.TryParse(reIndex, out n) ? n.ToString() : "1";
            }

            lock (temp)
            {
                string dFilePath = Server.MapPath(sVirtualPath + "UnderLine" + index + ".png");

                //判断图片是否存在
                #region 验证空格图片是否存在
                if (System.IO.File.Exists(dFilePath))
                {
                    Response.ClearContent(); //需要输出图象信息 要修改HTTP头
                    Response.ContentType = "image/Png";
                    Response.BinaryWrite(System.IO.File.ReadAllBytes(dFilePath));
                    Response.End();
                }
                #endregion

                #region 创建新空格图片
                else
                {
                    string filePath = Server.MapPath(sVirtualPath + "UnderLine.gif");
                    Bitmap bgImg = (Bitmap)Bitmap.FromFile(filePath);

                    int width = 36;
                    int height = 18;

                    Bitmap theBitmap = new Bitmap(width, height);
                    Graphics theGraphics = Graphics.FromImage(theBitmap);
                    theGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    theGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    theGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    theGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    //  白色背景
                    //theGraphics.Clear(Color.White);
                    theGraphics.DrawImage(bgImg, new Rectangle(0, 0, width, height), new Rectangle(0, 0, bgImg.Width, bgImg.Height), GraphicsUnit.Pixel);
                    //13pt的字体
                    float fontSize = height * 1.0f / 1.38f;
                    Font theFont = new Font("Arial", fontSize);
                    System.Drawing.Drawing2D.GraphicsPath gp = null;

                    int indLen = index.Length;

                    Point thePos = new Point((int)(fontSize - (indLen > 1 ? indLen * 2.5 : indLen * 2)), 2);
                    gp = new System.Drawing.Drawing2D.GraphicsPath();
                    gp.AddString(index, theFont.FontFamily, 0, fontSize, thePos, new StringFormat());

                    theGraphics.DrawPath(new Pen(Color.White, 2f), gp);
                    theGraphics.FillPath(new SolidBrush(Color.Red), gp);
                    theGraphics.ResetTransform();

                    if (gp != null) gp.Dispose();

                    //  将生成的图片发回客户端
                    MemoryStream ms = new MemoryStream();
                    theBitmap.Save(ms, ImageFormat.Png);

                    //保存文件
                    theBitmap.Save(dFilePath);

                    Response.ClearContent(); //需要输出图象信息 要修改HTTP头
                    Response.ContentType = "image/Png";
                    Response.BinaryWrite(ms.ToArray());
                    theGraphics.Dispose();
                    theBitmap.Dispose();
                    Response.End();
                }
                #endregion
            }

            return View();
        }
Beispiel #41
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isDrawing = false;

            pictureBox1.Refresh();

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, fontSize, theRectangle, new StringFormat());
            formGraphics.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
            formGraphics.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);

            labelState.Text = e.Location.X.ToString() + " , " + e.Location.Y.ToString();

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Wallpaper.BurnNewWallpaper(Wallpaper.wallpaperFile.FullName), SPIF_UPDATEINIFILE);
        }
Beispiel #42
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            labelState.Text = e.Location.X.ToString() + " , " + e.Location.Y.ToString();

            if (isDrawing)
            {
                pictureBox1.Refresh();
                Color newColor = Color.FromArgb(125, Color.Gray);

                Control control = (Control)sender;
                formGraphics = control.CreateGraphics();
                formGraphics.FillRectangle(new SolidBrush(newColor), theRectangle);
                formGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                theRectangle.X = startpoint.X;
                theRectangle.Y = startpoint.Y;
                theRectangle.Height = e.Y - startpoint.Y;
                theRectangle.Width = e.X - startpoint.X;

                fontSize = 96f;
                SizeF stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));

                if (theRectangle.Width > 15 && theRectangle.Height > 15)
                {
                    while (stringSize.Width > theRectangle.Width || stringSize.Height > theRectangle.Height)
                    {
                        stringSize = formGraphics.MeasureString(DateTime.Now.ToShortTimeString(), new Font(font.Name, fontSize));
                        fontSize -= 0.05f;
                    }

                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(DateTime.Now.ToShortTimeString(), font.FontFamily, (int)font.Style, fontSize, theRectangle, new StringFormat());
                    formGraphics.DrawPath(new Pen(HSL.GetComplementaryColor(color), 3f), path);
                    formGraphics.FillPath(new SolidBrush(Color.FromArgb(255, color)), path);

                    Settings.ChangeSetting(Settings.settings.fontSize, fontSize.ToString());
                    Wallpaper.fontSize = this.fontSize;
                }
            }
        }
Beispiel #43
0
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int i;
            double w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
            this.ForeColor = Color.Black;
            Brush brosse =new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            double deltax,deltay,voldeltax,voldeltay;
            double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1=new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();

            PointF[] points = new PointF[4] ;
               double angle=0,norme=0;
            double sinx = 0, cosx = 1;
            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {

                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));

                    p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
                    p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
                    p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
                    p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
                    p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
                    p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
                    p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
                    p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);

                    System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;

                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }

                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }

            }
            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
            {
                if (projet.reseaux[nproj].nodes[i].i != 0)
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
                }
            }*/
        }
Beispiel #44
0
        protected void GenerateImage()
        {
            Random random = new Random();
            // Create a new 32-bit bitmap image.
            Bitmap bitmap = new Bitmap(230,37,PixelFormat.Format32bppArgb);

            // Create a graphics object for drawing.
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Rectangle rect = new Rectangle(0, 0, 230, 37);

            // Fill in the background.
            System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent50, Color.LightGray, Color.White);
            //SolidBrush hatchBrush = new SolidBrush(Color.Red);

            String strText =(String)Session["ImageSID"];
            g.FillRectangle(hatchBrush, rect);

            // Set up the text font.
            SizeF size;
            float fontSize = rect.Height -12;
            // Adjust the font size until the text fits within the image.
             Font font = new Font("Century Schoolbook",fontSize, FontStyle.Bold);
                size = g.MeasureString(strText, font);
            // 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.
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(
              strText,
              font.FontFamily,
              (int)font.Style,
              font.Size, rect,
              format);
            float v = 12F;
            PointF[] points =
              {
            new PointF(
              random.Next(rect.Width) / v,
              random.Next(rect.Height) / v),
            new PointF(
              rect.Width - random.Next(rect.Width) / v,
              random.Next(rect.Height) / v),
            new PointF(
              random.Next(rect.Width) / v,
              rect.Height - random.Next(rect.Height) / v),
            new PointF(
              rect.Width - random.Next(rect.Width) / v,
              rect.Height - random.Next(rect.Height) / v)
              };
            //points={0,0,0,0};
            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0F);

            // Draw the text.
            hatchBrush = new System.Drawing.Drawing2D.HatchBrush(
              System.Drawing.Drawing2D.HatchStyle.Percent50,
              Color.LightSlateGray,
              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 = random.Next(rect.Width);
                int y = random.Next(rect.Height);
                int w = random.Next(m / 50);
                int h = random.Next(m / 50);
                g.FillEllipse(hatchBrush, x, y, w, h);
            }

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

            // Set the image.
            this.Response.Clear();
            this.Response.ContentType = "image/jpeg";

            // Write the image to the response stream in JPEG format.
            bitmap.Save(this.Response.OutputStream, ImageFormat.Jpeg);

            // Dispose of the CAPTCHA image object.
            bitmap.Dispose();
        }
        // load one single glyph into the cache
        private GlyphData Load(char glyph, FormatOptions formatOptions)
        {
            int fontId = GetFontId(IsAnsiChar(glyph) ? formatOptions.AnsiFont : formatOptions.Font);
            var font = m_registeredFonts[fontId];
            uint glyphId = ((uint)fontId << 16) + glyph;

            GlyphData glyphData;
            if (m_loadedGlyphs.TryGetValue(glyphId, out glyphData))
            {
                glyphData.m_timeStamp = m_timeStamp;
                return glyphData;
            }

            var str = glyph.ToString();
            var chRect = MeasureCharacter(glyph, m_registeredFonts[fontId].m_fontObject);
            chRect.Inflate(font.m_outlineThickness * 0.5f, font.m_outlineThickness * 0.5f);

            int width = Math.Max((int)Math.Ceiling(chRect.Width), 1);
            int height = Math.Max((int)Math.Ceiling(chRect.Height), 1);
            int pagesInX = (width - 1) / PageSize + 1;
            int pagesInY = (height - 1) / PageSize + 1;

            GlyphPage[] pages = new GlyphPage[pagesInX * pagesInY];
            for (int i = 0; i < pages.Length; ++i)
            {
                pages[i].m_x = i % pagesInX;
                pages[i].m_y = i / pagesInX;
                pages[i].m_pageIndex = RequestPage();
            }

            using (var bmp = new SystemDrawing.Bitmap(pagesInX * PageSize, pagesInY * PageSize))
            using (var g = SystemDrawing.Graphics.FromImage(bmp))
            using (var memStream = new MemoryStream())
            {
                // draw text using GDI+
                g.TextRenderingHint = SystemDrawing.Text.TextRenderingHint.AntiAliasGridFit;
                g.SmoothingMode = SystemDrawing.Drawing2D.SmoothingMode.AntiAlias;
                g.InterpolationMode = SystemDrawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                if (font.m_outlineThickness > 0)
                {
                    SystemDrawing.Pen outlinePen;
                    if (!m_outlinePensWithWidths.TryGetValue(font.m_outlineThickness, out outlinePen))
                    {
                        outlinePen = new SystemDrawing.Pen(SystemDrawing.Color.Gray, font.m_outlineThickness);
                        outlinePen.MiterLimit = font.m_outlineThickness;
                        m_outlinePensWithWidths.Add(font.m_outlineThickness, outlinePen);
                    }

                    // draw outline
                    using (var outlinePath = new SystemDrawing.Drawing2D.GraphicsPath())
                    {
                        outlinePath.AddString(str,
                            font.m_fontObject.FontFamily,
                            (int)font.m_fontObject.Style,
                            g.DpiX * font.m_fontObject.SizeInPoints / 72,
                            new SystemDrawing.PointF(-chRect.Left, -chRect.Top),
                            SystemDrawing.StringFormat.GenericDefault);
                        g.DrawPath(outlinePen, outlinePath);
                        g.FillPath(m_whiteBrush, outlinePath);
                    }
                }
                else
                {
                    g.DrawString(str, font.m_fontObject, m_whiteBrush, new SystemDrawing.PointF(-chRect.Left, -chRect.Top));
                }

                bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
                using (var tmpTexture = Texture2D.FromStream(GameApp.Instance.GraphicsDevice, memStream))
                {
                    var device = GameApp.Instance.GraphicsDevice;
                    device.DepthStencilState = DepthStencilState.None;
                    device.RasterizerState = RasterizerState.CullCounterClockwise;
                    device.Indices = null;

                    m_effect.CurrentTechnique = m_techBlit;
                    m_paramTexture.SetValue(tmpTexture);

                    foreach (var batch in pages.GroupBy(page => page.m_pageIndex / PagesInOneCacheTexture))
                    {
                        var textureId = batch.Key;
                        device.SetRenderTarget(m_cacheTextures[textureId].m_physicalRTTexture);
                        device.BlendState = m_channelMasks[textureId % 4];

                        var pagesInBatch = batch.ToArray();
                        var vertices = new VertexDataBlit[pagesInBatch.Length * 6];
                        for (int i = 0; i < pagesInBatch.Length; ++i)
                        {
                            var page = pagesInBatch[i];
                            var dstRectLeft = (page.m_pageIndex % PagesInOneCacheTexture) % PagesInOneRow * PageSize;
                            var dstRectTop = (page.m_pageIndex % PagesInOneCacheTexture) / PagesInOneRow * PageSize;

                            float posLeft = (dstRectLeft - 0.5f) / CacheTextureSize * 2 - 1;
                            float posTop = 1 - (dstRectTop - 0.5f) / CacheTextureSize * 2;
                            float posWidth = PageSize / (float)CacheTextureSize * 2;
                            float posHeight = -PageSize / (float)CacheTextureSize * 2;

                            float uvLeft = page.m_x / (float)pagesInX;
                            float uvTop = page.m_y / (float)pagesInY;
                            float uvWidth = 1.0f / pagesInX;
                            float uvHeight = 1.0f / pagesInY;

                            // left-top
                            vertices[i * 6 + 0].pos = new Vector2(posLeft, posTop);
                            vertices[i * 6 + 0].uv = new Vector2(uvLeft, uvTop);

                            // right-top
                            vertices[i * 6 + 1].pos = vertices[i * 6 + 4].pos = new Vector2(posLeft + posWidth, posTop);
                            vertices[i * 6 + 1].uv = vertices[i * 6 + 4].uv = new Vector2(uvLeft + uvWidth, uvTop);

                            // left-bottom
                            vertices[i * 6 + 2].pos = vertices[i * 6 + 3].pos = new Vector2(posLeft, posTop + posHeight);
                            vertices[i * 6 + 2].uv = vertices[i * 6 + 3].uv = new Vector2(uvLeft, uvTop + uvHeight);

                            // right-bottom
                            vertices[i * 6 + 5].pos = new Vector2(posLeft + posWidth, posTop + posHeight);
                            vertices[i * 6 + 5].uv = new Vector2(uvLeft + uvWidth, uvTop + uvHeight);
                        }

                        foreach (var pass in m_techBlit.Passes)
                        {
                            pass.Apply();
                            device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, pagesInBatch.Length * 2);
                        }
                    }

                    device.SetRenderTarget(null);
                }
            }

            glyphData = new GlyphData();
            glyphData.m_pageIndices = new int[pagesInX, pagesInY];
            pages.ForEach(page => glyphData.m_pageIndices[page.m_x, page.m_y] = page.m_pageIndex);
            glyphData.m_glyphSize = chRect.Size;
            glyphData.m_timeStamp = m_timeStamp;
            m_loadedGlyphs.Add(glyphId, glyphData);
            return glyphData;
        }
Beispiel #46
0
        //������̔������`��
        /// <summary>
        ///		������𔒔����ŕ`�悷��
        /// </summary>
        /// <param name="sString">�`�悷�镶����</param>
        /// <param name="x">������̍���[��X���W</param>
        /// <param name="y">������̍���[��Y���W</param>
        public void DrawStringWhiteBackground(string sString, int x, int y)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString(sString, new FontFamily(fFont.Name),0,fFont.Size,new Point(x,y),StringFormat.GenericDefault);

            //�������ɂ���
            pTarget.Graphics.FillPath(Brushes.White,gp);

            //�`��
            pTarget.Graphics.DrawPath(pPen,gp);
        }
Beispiel #47
0
        public static void RenderPreviewFont(Graphics g, Rectangle size, ITextSymbol item)
        {
            Font font;
            Color? foreground = null;
            Color? background = null;
            string text = string.Empty;
            BackgroundStyleType bgStyle;

            if (item == null || item.FontName == null)
            {
                font = new Font("Arial", 10.0f, FontStyle.Regular); //NOXLATE
                foreground = Color.Black;
                background = Color.White;
                text = Strings.EmptyText;
                bgStyle = BackgroundStyleType.Transparent;
            }
            else
            {
                try { font = new Font(item.FontName, 12); }
                catch { font = new Font("Arial", 12); } //NOXLATE
                try
                {
                    foreground = Utility.ParseHTMLColor(item.ForegroundColor);
                    background = Utility.ParseHTMLColor(item.BackgroundColor);
                }
                catch { }
                bgStyle = item.BackgroundStyle;

                FontStyle fs = FontStyle.Regular;
                if (item.Bold == "true") //NOXLATE
                    fs |= FontStyle.Bold;
                if (item.Italic == "true") //NOXLATE
                    fs |= FontStyle.Italic;
                if (item.Underlined == "true") //NOXLATE
                    fs |= FontStyle.Underline;
                font = new Font(font, fs);

                text = item.Text;
            }

            if (bgStyle == BackgroundStyleType.Ghosted)
            {
                using (System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                    pth.AddString(text, font.FontFamily, (int)font.Style, font.Size * 1.25f, size.Location, StringFormat.GenericDefault);

                    if (background.HasValue)
                    {
                        using (Pen p = new Pen(background.Value, 1.5f))
                            g.DrawPath(p, pth);
                    }

                    if (foreground.HasValue)
                    {
                        using (Brush b = new SolidBrush(foreground.Value))
                            g.FillPath(b, pth);
                    }
                }
            }
            else
            {
                if (bgStyle == BackgroundStyleType.Opaque)
                {
                    SizeF bgSize = g.MeasureString(text, font, new SizeF(size.Width, size.Height));
                    if (background.HasValue)
                    {
                        using (Brush b = new SolidBrush(background.Value))
                            g.FillRectangle(b, new Rectangle(size.Top, size.Left, (int)bgSize.Width, (int)bgSize.Height));
                    }
                }

                if (foreground.HasValue)
                {
                    using (Brush b = new SolidBrush(foreground.Value))
                        g.DrawString(text, font, b, size);
                }
            }
        }
Beispiel #48
0
        private void set_jimaku()
        {
            System.Drawing.Drawing2D.GraphicsPath path =
            new System.Drawing.Drawing2D.GraphicsPath();

            int style = 0;
            style += (text.Font.Bold) ? (int)FontStyle.Bold : (int)FontStyle.Regular;
            style += (text.Font.Italic) ? (int)FontStyle.Italic : (int)FontStyle.Regular;
            style += (text.Font.Underline) ? (int)FontStyle.Underline : (int)FontStyle.Regular;
            style += (text.Font.Strikeout) ? (int)FontStyle.Strikeout : (int)FontStyle.Regular;
            path.AddString(text.Text, text.Font.FontFamily,
                style,
                (float)(text.Font.SizeInPoints / 0.75), new Point(0, 0),
                StringFormat.GenericDefault);
            myForm.Region = new Region(path);
            myForm.BackColor = text.ForeColor;
            path.Dispose();
        }
        /// <summary>
        /// Draws labels in a specified rectangle
        /// </summary>
        /// <param name="g">The graphics object to draw to</param>
        /// <param name="labelText">The label text to draw</param>
        /// <param name="labelBounds">The rectangle of the label</param>
        /// <param name="symb">the Label Symbolizer to use when drawing the label</param>
        private static void DrawLabel(Graphics g, string labelText, RectangleF labelBounds, ILabelSymbolizer symb)
        {
            //Sets up the brushes and such for the labeling
            Brush foreBrush = new SolidBrush(symb.FontColor);
            Font textFont = symb.GetFont();
            StringFormat format = new StringFormat();
            format.Alignment = symb.Alignment;
            Pen borderPen = new Pen(symb.BorderColor);
            Brush backBrush = new SolidBrush(symb.BackColor);
            Brush haloBrush = new SolidBrush(symb.HaloColor);
            Pen haloPen = new Pen(symb.HaloColor);
            haloPen.Width = 2;
            haloPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset;
            Brush shadowBrush = new SolidBrush(symb.DropShadowColor);

            //Text graphics path
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString(labelText, textFont.FontFamily, (int)textFont.Style, textFont.SizeInPoints * 96F / 72F, labelBounds, format);

            //Draws the text outline
            if (symb.BackColorEnabled && symb.BackColor != Color.Transparent)
            {
                if (symb.FontColor == Color.Transparent)
                {
                    System.Drawing.Drawing2D.GraphicsPath backgroundGP = new System.Drawing.Drawing2D.GraphicsPath();
                    backgroundGP.AddRectangle(labelBounds);
                    backgroundGP.FillMode = System.Drawing.Drawing2D.FillMode.Alternate;
                    backgroundGP.AddPath(gp, true);
                    g.FillPath(backBrush, backgroundGP);
                    backgroundGP.Dispose();
                }
                else
                {
                    g.FillRectangle(backBrush, labelBounds);
                }
            }

            //Draws the border if its enabled
            if (symb.BorderVisible && symb.BorderColor != Color.Transparent)
                g.DrawRectangle(borderPen, labelBounds.X, labelBounds.Y, labelBounds.Width, labelBounds.Height);

            //Draws the drop shadow                      
            if (symb.DropShadowEnabled && symb.DropShadowColor != Color.Transparent)
            {
                System.Drawing.Drawing2D.Matrix gpTrans = new System.Drawing.Drawing2D.Matrix();
                gpTrans.Translate(symb.DropShadowPixelOffset.X, symb.DropShadowPixelOffset.Y);
                gp.Transform(gpTrans);
                g.FillPath(shadowBrush, gp);
                gpTrans = new System.Drawing.Drawing2D.Matrix();
                gpTrans.Translate(-symb.DropShadowPixelOffset.X, -symb.DropShadowPixelOffset.Y);
                gp.Transform(gpTrans);
            }

            //Draws the text halo
            if (symb.HaloEnabled && symb.HaloColor != Color.Transparent)
                g.DrawPath(haloPen, gp);

            //Draws the text if its not transparent
            if (symb.FontColor != Color.Transparent)
                g.FillPath(foreBrush, gp);

            //Cleans up the rest of the drawing objects
            shadowBrush.Dispose();
            borderPen.Dispose();
            foreBrush.Dispose();
            backBrush.Dispose();
            haloBrush.Dispose();
            haloPen.Dispose();
        }
Beispiel #50
0
        public System.Drawing.Bitmap GenerateMap( System.Drawing.Bitmap background = null )
        {
            int minx = int.MaxValue;
            int maxx = int.MinValue;
            int miny = int.MaxValue;
            int maxy = int.MinValue;
            int minz = int.MaxValue;
            int maxz = int.MinValue;
            foreach ( var spd in SearchPointDefinitions ) {
                minx = Math.Min( minx, spd.CoordX );
                miny = Math.Min( miny, spd.CoordY );
                minz = Math.Min( minz, spd.CoordZ );
                maxx = Math.Max( maxx, spd.CoordX );
                maxy = Math.Max( maxy, spd.CoordY );
                maxz = Math.Max( maxz, spd.CoordZ );
            }

            int extentx = maxx - minx;
            int extenty = maxy - miny;
            int extentz = maxz - minz;
            double factor = 0.05115;
            int padx = 222;
            int pady = 185;

            System.Drawing.Bitmap bmp;
            if ( background == null ) {
                bmp = new System.Drawing.Bitmap( (int)( extentx * factor + 1 + padx * 2 ), (int)( extentz * factor + 1 + pady * 2 ) );
            } else {
                bmp = new System.Drawing.Bitmap( background );
            }

            int idx = 1;
            foreach ( var spd in SearchPointDefinitions ) {
                if ( spd.Unknown11 != 1 ) { continue; } // not sure what these mean exactly but only the ones with an '1' here show up in game
                System.Drawing.Color color = System.Drawing.Color.Black;
                System.Drawing.Color border = System.Drawing.Color.White;
                switch ( spd.SearchPointType ) {
                    case 0: color = System.Drawing.Color.SpringGreen; border = System.Drawing.Color.Black; break; // tree stump
                    case 1: // shells
                        if ( spd.CoordY < 0 ) {
                            color = System.Drawing.Color.Red; // in water
                            border = System.Drawing.Color.White;
                        } else {
                            color = System.Drawing.Color.Aqua; // on beach
                            border = System.Drawing.Color.Black;
                        }
                        break;
                    case 2: color = System.Drawing.Color.FromArgb( 212, 212, 0 ); border = System.Drawing.Color.Black; break; // bones
                    case 3: color = System.Drawing.Color.DarkBlue; border = System.Drawing.Color.White; break; // seagulls
                }
                //SetPixelArea( bmp, (int)( ( spd.CoordX - minx ) * factor + padx ), (int)( ( extentz - ( spd.CoordZ - minz ) ) * factor + pady ), color, border );

                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                System.Drawing.StringFormat fmt = new System.Drawing.StringFormat( System.Drawing.StringFormatFlags.NoClip ) { Alignment = System.Drawing.StringAlignment.Center, LineAlignment = System.Drawing.StringAlignment.Center };
                //System.Drawing.Font font = new System.Drawing.Font( "Gentium Book", 32.0f, System.Drawing.GraphicsUnit.Pixel );
                int x = (int)( ( spd.CoordX - minx ) * factor + padx );
                int y = (int)( ( extentz - ( spd.CoordZ - minz ) ) * factor + pady );
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddString( idx.ToString(), new System.Drawing.FontFamily( "Gentium Book" ), (int)System.Drawing.FontStyle.Regular, 80.0f, new System.Drawing.Point( x, y + 4 ), fmt );
                g.DrawPath( new System.Drawing.Pen( border, 8 ), path );
                g.FillPath( new System.Drawing.SolidBrush( color ), path );
                g.Flush();
                ++idx;
            }

            return bmp;
        }
Beispiel #51
0
        private System.Drawing.Drawing2D.GraphicsPath GetSymbolOutlineByIndex(int symbolIndex)
        {
            System.Drawing.Drawing2D.GraphicsPath oOutline = new System.Drawing.Drawing2D.GraphicsPath();
            string sCharactor = new string(Convert.ToChar(symbolIndex), 1);
            oOutline.AddString(sCharactor, this._curFont.FontFamily, (int)FontStyle.Regular, this._fontSize, new Point(0, 0), StringFormat.GenericDefault);

            return oOutline;
        }
        /// <summary>
        /// 文字列をオフスクリーンに書き込みます。
        /// </summary>
        /// <param name="text">書き込む文字列</param>
        /// <param name="font"><paramref name="text"/> のフォント</param>
        /// <param name="color"><paramref name="text"/> の色</param>
        /// <param name="outlineColor"><paramref name="text"/> の縁取り色</param>
        /// <param name="rectangle"><paramref name="text"/> の書き込み位置及び範囲</param>
        internal void DrawText( string text, System.Drawing.Font font, System.Drawing.Brush color, System.Drawing.Pen outlineColor, System.Drawing.RectangleF rectangle )
        {
            using( var g = System.Drawing.Graphics.FromImage( OffScreen ) ) {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                if( outlineColor == null ) {
                    g.FillRectangle( System.Drawing.Brushes.Transparent, rectangle );
                    g.DrawString( text, font, color, rectangle );
                } else {
                    using( var gp = new System.Drawing.Drawing2D.GraphicsPath() ) {
                        var sizeInPixels = font.SizeInPoints * g.DpiY / 72;
                        gp.AddString( text, font.FontFamily, (int)font.Style, sizeInPixels, rectangle, null );
                        g.DrawPath( outlineColor, gp );
                        g.FillPath( color, gp );
                    }
                }
            }
        }