AddString() 공개 메소드

public AddString ( string s, FontFamily family, int style, float emSize, Point origin, StringFormat format ) : void
s string
family FontFamily
style int
emSize float
origin Point
format StringFormat
리턴 void
예제 #1
1
        static GraphicsPath GetStringPath(string s, float dpi, Point p, Font font, StringFormat format)
        {
            GraphicsPath path = new GraphicsPath();
            // Convert font size into appropriate coordinates
            float emSize = dpi * font.SizeInPoints / 72;
            path.AddString(s, font.FontFamily, (int)font.Style, emSize, p, format);

            return path;
        }
예제 #2
0
        public static void DrawText(Font font, StringFormat sf, GraphicsPath path, StringBuilder sb, bool isItalic, bool isBold, bool isUnderline, float left, float top, ref bool newLine, float leftMargin, ref int pathPointsStart)
        {
            var next = new PointF(left, top);

            if (path.PointCount > 0)
            {
                int k = 0;

                var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                for (int i = list.Length - 1; i >= 0; i--)
                {
                    if (list[i].X > next.X)
                        next.X = list[i].X;
                    k++;
                    if (k > 60)
                        break;
                    if (i <= pathPointsStart && pathPointsStart != -1)
                        break;
                }
            }

            if (newLine)
            {
                next.X = leftMargin;
                newLine = false;
                pathPointsStart = path.PointCount;
            }

            var fontStyle = FontStyle.Regular;
            if (isItalic)
                fontStyle |= FontStyle.Italic;
            if (isBold)
                fontStyle |= FontStyle.Bold;
            if (isUnderline)
                fontStyle |= FontStyle.Underline;

            try
            {
                path.AddString(sb.ToString(), font.FontFamily, (int)fontStyle, font.Size, next, sf);
            }
            catch
            {
                fontStyle = FontStyle.Regular;
                try
                {
                    path.AddString(sb.ToString(), font.FontFamily, (int)fontStyle, font.Size, next, sf);
                }
                catch
                {
                    path.AddString(sb.ToString(), new FontFamily("Arial"), (int)fontStyle, font.Size, next, sf);
                }
            }
            sb.Length = 0;
        }
예제 #3
0
        public void Draw(KalikoImage image) {
            var graphics = image.Graphics;
            var graphicsPath = new GraphicsPath();
            var stringFormat = new StringFormat {
                Alignment = Alignment,
                LineAlignment = VerticalAlignment
            };

            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            if (Font == null) {
                Font = image.Font ?? new Font("Arial", 32, FontStyle.Bold, GraphicsUnit.Pixel);
            }

            if (TargetArea == Rectangle.Empty) {
                TargetArea = new Rectangle(0, 0, image.Width, image.Height);
            }

            if (Point == Point.Empty) {
                graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, TargetArea, stringFormat);
            }
            else {
                graphicsPath.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Point, stringFormat);
            }

            if (Rotation != 0) {
                var rotationTransform = new Matrix(1, 0, 0, 1, 0, 0);
                var bounds = graphicsPath.GetBounds();
                rotationTransform.RotateAt(Rotation, new PointF(bounds.X + (bounds.Width / 2f), bounds.Y + (bounds.Height / 2f)));
                graphicsPath.Transform(rotationTransform);
            }

            if (TextShadow != null) {
                DrawShadow(graphics, graphicsPath);
            }

            if (Outline > 0) {
                var pen = new Pen(OutlineColor, Outline) {
                    LineJoin = LineJoin.Round
                };
                graphics.DrawPath(pen, graphicsPath);
            }

            if (TextBrush == null) {
                TextBrush = new SolidBrush(TextColor);
            }

            graphics.FillPath(TextBrush, graphicsPath);
        }
예제 #4
0
 private void Task1_Paint(object sender, PaintEventArgs e)
 {
     e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
     switch (_current)
     {
         case TextType.In:
             e.Graphics.DrawString("Sample", new Font("Arial", 50), new SolidBrush(Color.DarkSlateGray), 10, 75);
             e.Graphics.DrawString("Sample", new Font("Arial", 50), new SolidBrush(Color.Black), 12, 77);
             break;
         case TextType.Out:
             e.Graphics.DrawString("Sample", new Font("Arial", 50), new SolidBrush(Color.Black), 10, 75);
             e.Graphics.DrawString("Sample", new Font("Arial", 50), new SolidBrush(Color.DarkSlateGray), 12, 77);
             break;
         case TextType.Kon:
             GraphicsPath path = new GraphicsPath();
             path.AddString("Sample",
                 new FontFamily("Arial"),
                 (int) FontStyle.Italic,
                 50,
                 new Point(10, 75),
                 StringFormat.GenericDefault);
             e.Graphics.DrawPath(new Pen(Color.Black), path);
             break;
     }
 }
예제 #5
0
        /// <summary>
        /// Creating an image for a Captcha.
        /// </summary>
        /// <param name="captchaText">Text Captcha.</param>
        /// <returns></returns>
        public Bitmap Generate(string captchaText)
        {
            var bmp = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
            using (Graphics graphics = Graphics.FromImage(bmp))
            {
                var rect = new Rectangle(0, 0, Width, Height);
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                using (var solidBrush = new SolidBrush(Color.White))
                {
                    graphics.FillRectangle(solidBrush, rect);
                }

                //Randomly choose the font name.
                var family = _fonts[new Random().Next(0, _fonts.Length)];
                var font = new Font(family, 30);

                using (var fontFormat = new StringFormat())
                {
                    //Format the font in the center.
                    fontFormat.Alignment = StringAlignment.Center;
                    fontFormat.LineAlignment = StringAlignment.Center;

                    var path = new GraphicsPath();
                    path.AddString(captchaText, font.FontFamily, (int)font.Style, font.Size, rect, fontFormat);
                    using (var solidBrush = new SolidBrush(Color.Blue))
                    {
                        graphics.FillPath(solidBrush, DeformPath(path));
                    }

                }
                font.Dispose();

            }
            return bmp;
        }
예제 #6
0
        /// <summary>
        /// Renders text along the path
        /// </summary>
        /// <param name="self">The graphics object</param>
        /// <param name="halo">The pen to render the halo outline</param>
        /// <param name="fill">The brush to fill the text</param>
        /// <param name="text">The text to render</param>
        /// <param name="fontFamily">The font family to use</param>
        /// <param name="style">The style</param>
        /// <param name="emSize">The size</param>
        /// <param name="format">The format</param>
        /// <param name="ignoreLength"></param>
        /// <param name="path"></param>
        public static void DrawString(this Graphics self, Pen halo, Brush fill, string text, FontFamily fontFamily, int style, float emSize, StringFormat format, bool ignoreLength, GraphicsPath path)
        {
            if (path == null || path.PointCount == 0)
                return;

            var gp = new GraphicsPath();
            gp.AddString(text, fontFamily, style, emSize, new Point(0, 0), format);

            SortedList<float, GraphSegment> edges;
            var totalLength = GetPathLength(path, out edges);

            var warpedPath = PrepareTextPathToWarp(gp, totalLength, ignoreLength, format);

            if (warpedPath == null)
                return;

            var wp = Warp(path, warpedPath, false, 0f);
            if (wp != null)
            {
                if (halo != null)
                    self.DrawPath(halo, wp);
                if (fill != null)
                    self.FillPath(fill, wp);
            }
        }
        private static Bitmap CreateInfomationBitmap(string content, int width, int height,
			StringAlignment hAlign = StringAlignment.Near,
			StringAlignment vAlign = StringAlignment.Near)
        {
            Bitmap b = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(b);
            GraphicsPath path = new GraphicsPath();
            FontFamily fontFamily = new FontFamily("微软雅黑");
            StringFormat format = new StringFormat();
            format.Alignment = hAlign;
            format.LineAlignment = vAlign;
            path.AddString(content,
                fontFamily, (int)FontStyle.Bold, 16, new Rectangle(0, 0, width, height), format);
            fontFamily.Dispose();
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.Black, path);
            Pen pen = new Pen(Color.Black, 2);
            g.DrawPath(pen, path);
            g.Dispose();
            pen.Dispose();
            Bitmap infoBitmap = RenderUtils.BoxBlur(b, 1);
            g = Graphics.FromImage(infoBitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(Brushes.White, path);
            g.Dispose();
            return infoBitmap;
        }
예제 #8
0
        protected override void OnPaint(PaintEventArgs e) {
            if (DesignMode || !Natives.CanUseAero) {
                base.OnPaint(e);
                return;
            }

            using (Bitmap b = new Bitmap(Width / 5, Height / 5))
            using (GraphicsPath path = new GraphicsPath())
            using (Graphics temp = Graphics.FromImage(b))
            using (Pen glow = new Pen(Color.Red, 3))
            using (Brush text = new SolidBrush(Color.Black))
            using (Matrix matrix = new Matrix(1.0f / 5, 0, 0, 1.0f / 5, -(1.0f / 5), -(1.0f / 5))) {

                path.AddString(Text, Font.FontFamily, (int)Font.Style, Font.Size, Location, StringFormat.GenericTypographic);
                temp.SmoothingMode = SmoothingMode.AntiAlias;
                temp.Transform = matrix;
                temp.DrawPath(glow, path);
                temp.FillPath(Brushes.Red, path);

                e.Graphics.Transform = new Matrix(1, 0, 0, 1, 50, 50);
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                e.Graphics.DrawImage(b, ClientRectangle, 0, 0, b.Width, b.Height, GraphicsUnit.Pixel);
                e.Graphics.FillPath(text, path);
            }

        }
예제 #9
0
파일: form1.cs 프로젝트: yasirbhutta/docs
    //</snippet3>

    // The following code example demonstrates using a Matrix
    // and the GraphicsPath.Transform method to rotate a string.
    // This example is designed to be used with Windows Forms.
    // Create a form and paste the following code into it. Call the
    // DrawVerticalStringFromBottomUp method in the form's Paint
    // event-handling method, passing e as PaintEventArgs.
    //<snippet5>
    public void DrawVerticalStringFromBottomUp(PaintEventArgs e)
    {
        // Create the string to draw on the form.
        string text = "Can you read this?";

        // Create a GraphicsPath.
        System.Drawing.Drawing2D.GraphicsPath path =
            new System.Drawing.Drawing2D.GraphicsPath();

        // Add the string to the path; declare the font, font style, size, and
        // vertical format for the string.
        path.AddString(text, this.Font.FontFamily, 1, 15,
                       new PointF(0.0F, 0.0F),
                       new StringFormat(StringFormatFlags.DirectionVertical));

        // Declare a matrix that will be used to rotate the text.
        System.Drawing.Drawing2D.Matrix rotateMatrix =
            new System.Drawing.Drawing2D.Matrix();

        // Set the rotation angle and starting point for the text.
        rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F));

        // Transform the text with the matrix.
        path.Transform(rotateMatrix);

        // Set the SmoothingMode to high quality for best readability.
        e.Graphics.SmoothingMode =
            System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        // Fill in the path to draw the string.
        e.Graphics.FillPath(Brushes.Red, path);

        // Dispose of the path.
        path.Dispose();
    }
예제 #10
0
파일: Text.cs 프로젝트: alexturpin/Zombles
        protected virtual void UpdateImage()
        {
            using (var ctx = Graphics.FromImage(BitmapTexture2D.Blank.Bitmap)) {
                var size = ctx.MeasureString(Value, Font);
                SubrectWidth = (float) Math.Ceiling(size.Width);
                SubrectHeight = (float) Math.Ceiling(size.Height);
            }

            if (Texture.Bitmap.Width < SubrectWidth || Texture.Bitmap.Height < SubrectHeight) {
                if (Texture != BitmapTexture2D.Blank) Texture.Dispose();

                int newWidth = Math.Max((int) SubrectWidth, Texture.Bitmap.Width);
                int newHeight = Math.Max((int) SubrectHeight, Texture.Bitmap.Height);

                Texture = new BitmapTexture2D(MathHelper.NextPowerOfTwo(newWidth), MathHelper.NextPowerOfTwo(newHeight));
            }

            using (var ctx = Graphics.FromImage(Texture.Bitmap)) {
                ctx.SmoothingMode = SmoothingMode.HighQuality;
                ctx.Clear(Color.Transparent);

                var path = new GraphicsPath();

                path.AddString(Value, Font.FontFamily, (int) Font.Style,
                    ctx.DpiY * Font.Size / 72f, PointF.Empty, StringFormat.GenericDefault);

                ctx.FillPath(_brush, path);
            }

            Texture.Invalidate();
        }
예제 #11
0
        public OutlinedStringSurface(
            String str, Font font, Brush brush, Pen outlinePen,
            StringFormat stringFormat)
        {
            Contract.Requires(str != null);
            Contract.Requires(font != null);
            Contract.Requires(brush != null);
            Contract.Requires(outlinePen != null);

            _brush = brush;
            _outlinePen = outlinePen;

            // グラフィックスパスの生成
            _path = new GraphicsPath();
            _path.AddString(
                str, font.FontFamily, (int)font.Style, font.Size,
                new Point(0, 0), stringFormat);
            // サイズを取得する
            var rect = _path.GetBounds();
            Size = rect.Size.ToSize();
            // 描画時にマージンがなくなるように平行移動
            var matrix = new Matrix(1, 0, 0, 1, -rect.Left, -rect.Top);
            _path.Transform(matrix);
            // 描画位置を(0, 0)で記憶
            matrix.Reset();
            _matrix = matrix;
        }
예제 #12
0
        public static void DrawStringWithGraphicsPath(this Graphics g, string text, Font font, Brush brush, RectangleF rect, StringFormat format, bool allowNarrowSetWidth = false)
        {
            var state = g.Save();

            SizeF sz2 = g.MeasureString(text, font);
            float width = sz2.Width;

            if (width > rect.Width && allowNarrowSetWidth)
            {
                float mag = rect.Width / width;

                g.TranslateTransform(rect.Left, 0f);
                g.TranslateTransform(-rect.Width * mag * 0.5f, 0f);
                g.ScaleTransform(mag, 1f);
                g.TranslateTransform(rect.Width * 0.5f, 0f);
                g.TranslateTransform(-rect.Left, 0f);

                rect.Width = rect.Width / mag;
            }

            float emSize = g.DpiY * font.Size / 72; // 다른의견 = font.Size + 4;
            GraphicsPath gp = new GraphicsPath();
            gp.AddString(text, font.FontFamily, (int)font.Style, emSize, rect, format);

            g.FillPath(brush, gp);
            g.Restore(state);
        }
예제 #13
0
파일: Captcha.cs 프로젝트: evkap/DVS
		public Bitmap GenerateImage()
		{
			int a = random.Next(_maxNumber);
			int b = random.Next(_maxNumber);
			_answer = (a + b).ToString();
			string text = string.Format("{0} + {1} = ", a, b);

			Bitmap bitmap = new Bitmap(_width, _height, PixelFormat.Format32bppArgb);
			Graphics g = Graphics.FromImage(bitmap);
			g.SmoothingMode = SmoothingMode.AntiAlias;
			Rectangle rect = new Rectangle(0, 0, _width, _height);
			HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, _foreColor, _bgColor);
			g.FillRectangle(hatchBrush, rect);

			SizeF size;
			float fontSize = rect.Height + 1;
			Font font;
			do
			{
				fontSize--;
				font = new Font(_familyName, fontSize, FontStyle.Bold);
				size = g.MeasureString(text, font);
			} while (size.Width > rect.Width);

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

			// Create a path using the text and warp it randomly.
			GraphicsPath path = new GraphicsPath();
			path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, format);
			float v = 4F;
			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)
			};
			Matrix matrix = new Matrix();
			matrix.Translate(0F, 0F);
			path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

			hatchBrush = new HatchBrush(HatchStyle.SolidDiamond, _foreColor, _foreColor);
			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);
			}

			return bitmap;
		}
예제 #14
0
        public Subtitle(string content,
			Font font, Color fillColor, Color borderColor, float borderWidth,
			long startTime, long endTime)
        {
            StartTime = startTime;
            EndTime = endTime;

            IntPtr screenDc = ApiHelper.GetDC(IntPtr.Zero);
            Graphics g = Graphics.FromHdc(screenDc);
            SizeF gsize = g.MeasureString(content, font);
            g.Dispose();
            this.Size = Size.Ceiling(new SizeF(gsize.Width + borderWidth, gsize.Height + borderWidth));

            hMemDc = ApiHelper.CreateCompatibleDC(screenDc);
            hMemBitmap = ApiHelper.CreateCompatibleBitmap(screenDc, Size.Width, Size.Height);
            ApiHelper.ReleaseDC(IntPtr.Zero, screenDc);
            ApiHelper.SelectObject(hMemDc, hMemBitmap);
            g = Graphics.FromHdc(hMemDc);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            GraphicsPath path = new GraphicsPath();
            path.AddString(content, font.FontFamily, (int)font.Style, font.Size,
                new Rectangle(Point.Empty, Size), defaultFormat);

            Pen pen = new Pen(borderColor, borderWidth);
            pen.LineJoin = LineJoin.Round;
            pen.Alignment = PenAlignment.Outset;
            g.DrawPath(pen, path);
            pen.Dispose();
            Brush brush = new SolidBrush(fillColor);
            g.FillPath(brush, path);
            brush.Dispose();
            g.Dispose();
        }
 public virtual void Draw(Graphics g)
 {
     GraphicsPath usepath = new GraphicsPath();
     usepath.AddString(usecharacter.ToString(), useFont.FontFamily, (int)useFont.Style, useFont.Size, currentposition,StringFormat.GenericDefault);
     g.FillPath(fillbrush, usepath);
     g.DrawPath(strokepen, usepath);
 }
예제 #16
0
        public override bool DrawString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int fontSize,
            string strText,
            System.Drawing.Point ptDraw,
            System.Drawing.StringFormat strFormat)
        {
            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);

                for (int i = 1; i <= m_nThickness; ++i)
                {
                    using (Pen pen = new Pen(m_clrOutline, i))
                    {
                        pen.LineJoin = LineJoin.Round;
                        graphics.DrawPath(pen, path);
                    }
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
                else
                    graphics.FillPath(m_brushText, path);
            }
            return true;
        }
예제 #17
0
        private void DrawText(PaintEventArgs pe)
        {
            if (base.Text == null || base.Text.Trim() == "" || pe == null || base.Font == null || base.ForeColor == null) {
                return;
            }

            PointF DrawPoint = new PointF(0,base.Height /2);

            pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            pe.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            SolidBrush Brush = new SolidBrush(base.ForeColor);
            FontFamily fontFamily = base.Font.FontFamily;
            StringFormat strf = new StringFormat();
            //			strf.Alignment = StringAlignment.;
            strf.LineAlignment = StringAlignment.Center;
            GraphicsPath path = new GraphicsPath();

            String drstr = Text.Replace('_', ' ');

            path.AddString(drstr, fontFamily, (int) FontStyle.Regular, 10.0f, DrawPoint, strf);

            Pen pen = new Pen(Color.FromArgb(90, 90, 90), 3);
            pe.Graphics.DrawPath(pen,path);
            pe.Graphics.FillPath(Brush,path);
        }
예제 #18
0
        private void DrawOutline(Graphics e, Rectangle rect)
        {
            //out line
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding);
            path.AddString(Content, Font.FontFamily, (int)Font.Style, Font.Size, rect, StringFormat);

            //draw the outline
            Pen pen = new Pen(OutlineColor, OutlineSize);

            if (OutlineSize == 0)
            {
                pen = new Pen(OutlineColor);
            }

            pen.LineJoin        = OutlineStyle;
            e.SmoothingMode     = SmoothingMode.AntiAlias;
            e.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            e.PixelOffsetMode   = PixelOffsetMode.HighQuality;

            int       offetX     = (int)OutlineSize;
            int       offetY     = (int)OutlineSize;
            Rectangle shadowRect = new Rectangle(rect.X, rect.Y,
                                                 rect.Width + offetX, rect.Height + offetY);

            e.DrawPath(pen, path);
            e.FillPath(new SolidBrush(TextColor), path);
            pen.Dispose();
        }
예제 #19
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">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="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
예제 #20
0
 public Form1()
 {
     InitializeComponent();
     Path = new GraphicsPath();
     StringFormat sm = new StringFormat();
     Path.AddString("한", new FontFamily("궁서"), 0, 200, new Point(10, 10), sm);
 }
예제 #21
0
		/// <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);
			}
		}
예제 #22
0
        public static Bitmap BitmapFromText(string text, Font f, Color col, Color glowCol, Rectangle rect, float glowScale)
        {
            Bitmap bm = new Bitmap((int)(rect.Width / glowScale), (int)(rect.Height / glowScale));
            GraphicsPath pth = new GraphicsPath();
            pth.AddString(text, f.FontFamily, (int)f.Style, f.Size, new Point(rect.Left, rect.Top), StringFormat.GenericTypographic);
            Graphics g = Graphics.FromImage(bm);
            Matrix mx = new Matrix(1.0f / glowScale, 0, 0, 1.0f / glowScale, -(1.0f / glowScale), -(1.0f / glowScale));
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.Transform = mx;
            Pen p = new Pen(glowCol, 3);
            g.DrawPath(p, pth);
            g.FillPath(new SolidBrush(glowCol), pth);
            g.Dispose();

            Bitmap bmp = new Bitmap(rect.Width, rect.Height);
            Graphics g2 = Graphics.FromImage(bmp);
            g2.Transform = new Matrix(1, 0, 0, 1, 50, 50);
            g2.SmoothingMode = SmoothingMode.AntiAlias;
            g2.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g2.DrawImage(bm, rect, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel);
            g2.FillPath(new SolidBrush(col), pth);
            pth.Dispose();

            return bmp;
        }
예제 #23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (BorderRadius == 0)
            {
                Rectangle rc = ClientRectangle;
                rc.Inflate(-(int)Math.Round(BorderWidth / 2.0 + .5), -(int)Math.Round(BorderWidth / 2.0 + .5));

                rc.Y = rc.Y - 1;
                rc.Height = rc.Height + 1;

                e.Graphics.DrawRectangle(new Pen(BorderColor, BorderWidth), rc);
            }
            else
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                GraphicsPath gp = Extensions.Create(0, 0, Width - 2, Height - 2, BorderRadius);
                Pen p = new Pen(BorderColor, BorderWidth);

                e.Graphics.DrawPath(p, gp);
                e.Graphics.FillPath(p.Brush, gp);

                StringFormat formatting = (StringFormat)StringFormat.GenericTypographic.Clone();
                formatting.Alignment = StringAlignment.Center;
                formatting.LineAlignment = StringAlignment.Center;

                float emsize = e.Graphics.DpiY * Font.Size / 72;
                gp = new GraphicsPath();
                gp.StartFigure();
                gp.AddString(Text, Font.FontFamily, (int)Font.Style, emsize, new Point(Width / 2, Height / 2), formatting);
                gp.CloseFigure();
                e.Graphics.FillPath(new Pen(ForeColor, 1).Brush, gp);
            }
        }
예제 #24
0
        /// <summary>
        /// Draw an outlined text on a graphic.
        /// Draw a text using an outline in it, from custom CardGraphicComponent values. These are used to get position of text and destination picture/graphic.
        /// </summary>
        /// <param name="g">Graphic to draw the text</param>
        /// <param name="text">Text to draw</param>
        /// <param name="canvas">Values for position, font, etc. of the text</param>
        /// <param name="parent">If canvas has a parent, use it for relative position of the text</param>
        /// <param name="centered">If text must be drawn centered or not</param>
        public static void drawOutlineText(Graphics g, string text, CardGraphicComponent canvas, CardGraphicComponent parent, bool centered=false)
        {
            // Check parent to get proper offsets
            var offsetTop  = 0;
            var offsetLeft = 0;
            if (parent != null)
            {
                offsetLeft = parent.Left;
                offsetTop  = parent.Top;
            }
            // set atialiasing for drawing
            g.SmoothingMode     = SmoothingMode.HighQuality; // AntiAlias
            g.InterpolationMode = InterpolationMode.HighQualityBicubic; // High
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            // Create GraphicsPath to draw text
            using (GraphicsPath path = new GraphicsPath())
            {
                // Calculate position in case text must be draw centered or not
                float txtWidth = 0;
                if (centered)
                    txtWidth = getStringWidth(g, text, new Font(canvas.font.FontFamily, canvas.font.Size, canvas.font.Style, GraphicsUnit.Point, ((byte)(0)))) / 2;
                // Add string to path
                path.AddString(text, canvas.font.FontFamily, (int)canvas.font.Style, canvas.font.Size, new Point(canvas.Left + offsetLeft - (int)txtWidth, canvas.Top + offsetTop), StringFormat.GenericTypographic);
                // Draw text using this pen. This does the trick (with the path) to draw the outline
                using (Pen pen = new Pen(canvas.borderColor, canvas.Outline))
                {
                    pen.LineJoin = LineJoin.Round;

                    g.DrawPath(pen, path);
                    g.FillPath(canvas.textColor, path);
                }
            }
        }
예제 #25
0
        public override bool DrawString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int fontSize,
            string strText,
            System.Drawing.Point ptDraw,
            System.Drawing.StringFormat strFormat)
        {
            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
                else
                    graphics.FillPath(m_brushText, path);
            }
            return true;
        }
예제 #26
0
        void FormSplashScreen_Paint(object sender, PaintEventArgs e) {

            if ( Natives.CanUseAero ) {
                Natives.FillBlackRegion(e.Graphics, ClientRectangle);
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                var gDevPath = new GraphicsPath();
                var gLogPath = new GraphicsPath();
                var brush = new SolidBrush(Color.FromArgb(0x99, Color.Black));

                gDevPath.AddString(_devList, DrawingFont.FontFamily, (int)FontStyle.Regular, Constants.DEV_TEXT_SIZE,
                                                    new Point(Constants.LOGO_WIDTH + Constants.PADDING, Constants.TEXT_HEIGHT + Constants.PADDING), StringFormat.GenericDefault);

                gLogPath.AddString(LogMessage, DrawingFont.FontFamily, (int)FontStyle.Bold, Constants.LOG_TEXT_SIZE, new Point(Constants.PADDING, Height - 65 - Constants.PADDING), StringFormat.GenericDefault);

                e.Graphics.DrawImage(HammerBitmap, Constants.PADDING, Constants.PADDING, Constants.LOGO_WIDTH, Constants.LOGO_HEIGHT);
                e.Graphics.DrawImage(MCForgeBitmap, Constants.LOGO_WIDTH + Constants.PADDING, Constants.PADDING, Constants.TEXT_WIDTH, Constants.TEXT_HEIGHT);
                e.Graphics.FillPath(brush, gDevPath);
                e.Graphics.FillPath(brush, gLogPath);


                gDevPath.Dispose();
                gLogPath.Dispose();
                brush.Dispose();
            }
        }
예제 #27
0
        public void Gen(List<BiliInterfaceInfo> infos)
        {
            Log.Info("【主榜】开始生成" + infos.Count + "个图片");

            for (int i = 0; i < infos.Count; i++)
            {
                image = Properties.Resources.zhubang;
                g = Graphics.FromImage(image);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                ////
                Log.Info("正在生成 - " + infos[i].AVNUM);

                g.DrawString(infos[i].title, f, b, 350, 1000);
                g.DrawString(infos[i].AVNUM, f, b, 375, 900);
                g.DrawString(infos[i].created_at.Substring(0, infos[i].created_at.IndexOf(" ")), f, b, 900, 900);
                g.DrawString("UP:" + infos[i].author, f, b, 330, 800);

                Pen pp = new Pen(Color.Yellow, 3.5f);
                GraphicsPath pth = new GraphicsPath();
                pth.AddString(infos[i].Fpaiming.ToString("D2"), new FontFamily("微软雅黑"), (int)FontStyle.Bold, 180, new Point(1750, 0), sf);
                g.FillPath(new SolidBrush(Color.White), pth);
                g.DrawPath(pp, pth);

                AddKongxin(infos[i].Fdefen.ToString(), 160, 960, 70);
                AddKongxin(infos[i].play.ToString(), 1625, 500, 70);
                AddKongxin(infos[i].review.ToString(), 1820, 330, 50);
                AddKongxin(infos[i].coins.ToString(), 1810, 710, 50);
                AddKongxin(infos[i].favorites.ToString(), 1600, 825, 60);

                /*
                g.DrawString(infos[i].Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);

                g.DrawString(infos[i].AVNUM.Substring(2), f, b, 725, nn);
                g.DrawString(infos[i].Fdefen.ToString(), f, b, 1160, nn);
                if (infos[i].author.Length <= 6)
                {
                    g.DrawString(infos[i].author, f, b, new RectangleF(1518, nn, 320, 320));
                    //g.DrawString(infos[i].up, f, b, 1518, nn);
                }
                else
                {
                    g.DrawString(infos[i].author, f, b, new RectangleF(1518, nn, 320, 320));
                    //g.DrawString(infos[i].up.Substring(0, 6), f, b, 1518, nn);
                    //g.DrawString(infos[i].up.Substring(6), f, b, 1518, nn + 74);
                }

                g.DrawString(infos[i].created_at, f, b, 880, nn + 148);
                */

                ////

                string url = Environment.CurrentDirectory + @"\pic\Rank" + infos[i].Fpaiming + ".png";
                Log.Info("保存图片 " + url);
                image.Save(url);
            }

            Log.Info("主榜图片批量生成完成");
        }
예제 #28
0
        private static System.Drawing.Drawing2D.GraphicsPath GetStringPath(string text, float dpi, Font font, PointF point)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            float emSize = font.Size * 1.38f;

            path.AddString(text, font.FontFamily, (int)font.Style, emSize, point, StringFormat.GenericTypographic);
            return(path);
        }
예제 #29
0
파일: Form2.cs 프로젝트: sunnamkim/doc
        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            //패스 그래디언트
            Point[] pts = { new Point(100, 0), new Point(0, 100), new Point(200, 100) };
            PathGradientBrush B = new PathGradientBrush(pts, WrapMode.Tile);
            e.Graphics.FillRectangle(B, ClientRectangle);

            //패스 그래디언트 끝
            //패스변형
            GraphicsPath Path = new GraphicsPath();
            Path.AddString("한글", new FontFamily("궁서"), 0, 100, new Point(10, 30), new StringFormat());
            //확장 후 외곽선 그리기
            Path.Widen(new Pen(Color.Black, 3));
            e.Graphics.DrawPath(Pens.Black, Path);

            //확장 후 채우기
            Path.Widen(new Pen(Color.Blue, 3));
            e.Graphics.DrawPath(Pens.Black, Path);

            //곡선 펴기
            Path.Flatten(new Matrix(), 12f);
            e.Graphics.DrawPath(Pens.Black, Path);

            //회전
            Matrix M = new Matrix();
            M.Rotate(-10);
            Path.Transform(M);
            e.Graphics.FillPath(Brushes.Blue, Path);

            //휘기
            RectangleF R = Path.GetBounds();
            PointF[] arPoint = new PointF[4];
            arPoint[0] = new PointF(R.Left, R.Top + 30);
            arPoint[1] = new PointF(R.Right, R.Top - 10);
            arPoint[2] = new PointF(R.Left + 10, R.Bottom - 10);
            arPoint[3] = new PointF(R.Right + 30, R.Bottom + 30);

            Path.Warp(arPoint, R);
            e.Graphics.FillPath(Brushes.Blue, Path);

            //클리핑

            //graphicspath path= new graphicspath();
            //path.fillmode = fillmode.winding;
            //path.addellipse(50, 10, 100, 80);
            //path.addellipse(20, 45, 160, 120);
            //e.graphics.fillpath(brushes.white, path);

            //e.graphics.setclip(path);

            //for (int y = 0; y < bottom; y+= 20)
            //{
            //    string str = "눈사람의 모양의클리핑 영역에 글자를 쓴것입니다";
            //    e.graphics.drawstring(str, font, brushes.blue, 0, y);
            //}

            //클리핑 끝
        }
        public override Bitmap Build(string text)
        {
            var random = new Random();
            var bitmap = new Bitmap
                (Width, Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bitmap);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            var rect = new Rectangle(0, 0, Width, Height);
            var hatchBrush = new HatchBrush(HatchStyle.SmallConfetti,
                Color.LightGray, Color.White);
            g.FillRectangle(hatchBrush, rect);
            SizeF size;
            float fontSize = rect.Height + 1;
            Font font;

            do
            {
                fontSize--;
                font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold);
                size = g.MeasureString(text, font);
            } while (size.Width > rect.Width);
            var format = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};
            var path = new GraphicsPath();
            //path.AddString(this.text, font.FontFamily, (int) font.Style,
            //    font.Size, rect, format);
            path.AddString(text, font.FontFamily, (int) font.Style, 75, rect, format);
            float v = 4F;
            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)
            };
            var matrix = new Matrix();
            matrix.Translate(0F, 0F);
            path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);
            hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue);
            g.FillPath(hatchBrush, path);
            int m = Math.Max(rect.Width, rect.Height);
            for (int i = 0; i < (int) (rect.Width*rect.Height/30F); i++)
            {
                int x = 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);
            }
            font.Dispose();
            hatchBrush.Dispose();
            g.Dispose();
            return bitmap;
        }
예제 #31
0
 private void button2_Click(object sender, EventArgs e)
 {
     Graphics g = this.CreateGraphics();
     GraphicsPath path = new GraphicsPath(FillMode.Winding);
     path.AddString("你好世界", new FontFamily("华文琥珀"), (int)FontStyle.Regular,
         80, new PointF(10, 20), new StringFormat());
     Brush brush = new LinearGradientBrush(new PointF(0, 0), new PointF(Width, Height), Color.Red, Color.Yellow);
     g.DrawPath(Pens.Black, path);
     g.FillPath(brush, path);
 }
예제 #32
0
        private static void DrawTestLegenda(Graphics monitorGraphics, ScaledScreen scaledScreen)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            System.Drawing.Pen        redPen    = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            System.Drawing.Pen        yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            System.Drawing.SolidBrush brush     = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            Rectangle legendaRect = new Rectangle((int)400, (int)400, 400, 400);

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString("PhotoDesktop",
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           40,
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, 80),
                           stringFormat);
            path.AddString(string.Format("Scale {0}", scaledScreen.Scale),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           20,
                           new Rectangle(legendaRect.X, legendaRect.Y + 80, legendaRect.Width, 20),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", scaledScreen.Width, scaledScreen.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           20,
                           new Rectangle(legendaRect.X, legendaRect.Y + 100, legendaRect.Width, 20),
                           stringFormat);


            Color textColor = Color.FromArgb(0, 0, 0);
            Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #33
0
        private GraphicsPath PrepLetter(string letter)
        {
            // FontFamily ff = new FontFamily("1CamBam_Stick_2");
            // FontFamily ff = new FontFamily("Kunstler Script");
            // FontFamily ff = new FontFamily("Arial");
            FontFamily   ff = new FontFamily("Kristen ITC");
            GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddString(letter, ff, (int)FontStyle.Regular, 350, new Point(0, 0), StringFormat.GenericTypographic);
            return(gp);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Guard.NotNull(e, nameof(e));

            Rectangle clientBounds = Reflected.DeflateRect(ClientRectangle, Padding);

            if (string.IsNullOrWhiteSpace(Text))
            {
                e.Graphics.Clear(BackColor);

                if (Image != null)
                {
                    Rectangle imageBounds = Rectangle.Round(clientBounds);
                    DrawImage(e.Graphics, Image, imageBounds, RtlTranslateAlignment(ImageAlign));
                }
            }
            else
            {
                using (StringFormat stringFormat = Reflected.GetStringFormat(this))
                {
                    using (var textPath = new GraphicsPath())
                    {
                        textPath.AddString(Text, Font.FontFamily, (int) Font.Style, clientBounds.Height, TopLeftPoint,
                            stringFormat);

                        PointF[] transformPoints =
                        {
                            new PointF(clientBounds.Left, clientBounds.Top),
                            new PointF(clientBounds.Right, clientBounds.Top),
                            new PointF(clientBounds.Left, clientBounds.Bottom)
                        };
                        RectangleF textBounds = Stabilize(textPath.GetBounds());
                        e.Graphics.Transform = new Matrix(textBounds, transformPoints);

                        e.Graphics.Clear(BackColor);
                        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

                        if (Image != null)
                        {
                            Rectangle imageBounds = Rectangle.Round(textBounds);
                            DrawImage(e.Graphics, Image, imageBounds, RtlTranslateAlignment(ImageAlign));
                        }

                        using (var brush = new SolidBrush(Enabled ? ForeColor : ControlPaint.LightLight(ForeColor)))
                        {
                            e.Graphics.FillPath(brush, textPath);
                        }

                        e.Graphics.ResetTransform();
                    }
                }
            }
        }
예제 #35
0
파일: Letter.cs 프로젝트: skoryupina/BESEDa
 protected override void OnPaint(PaintEventArgs e)
 {
     GraphicsPath myGraphicsPath = new GraphicsPath();
     //string stringText = Letterl;
     FontFamily family = new FontFamily("Arial");
     int fontStyle = (int)FontStyle.Bold;
     int emSize = fontSize*2;
     PointF origin = new PointF(0, 0);
     StringFormat format = new StringFormat(StringFormat.GenericDefault);
     myGraphicsPath.AddString(Letterl, family, fontStyle, emSize, origin, format);
     this.Region = new Region(myGraphicsPath);
    
 }
예제 #36
0
        public void Render(string challengeGuid)
        {
            // Retrieve the solution text from Session[]
            string key = CaptchaHelper.SessionKeyPrefix + challengeGuid;
            string solution = (string)HttpContext.Session[key];

            if (solution != null)
            {
                // Make a blank canvas to render the CAPTCHA on
                using (Bitmap bmp = new Bitmap(ImageWidth, ImageHeight))
                using (Graphics g = Graphics.FromImage(bmp))
                using (Font font = new Font(FontFamily, 1f))
                {
                    g.Clear(Background);

                    // Perform trial rendering to determine best font size
                    SizeF finalSize;
                    SizeF testSize = g.MeasureString(solution, font);
                    float bestFontSize = Math.Min(ImageWidth / testSize.Width,
                                            ImageHeight / testSize.Height) * 0.95f;

                    using (Font finalFont = new Font(FontFamily, bestFontSize))
                    {
                        finalSize = g.MeasureString(solution, finalFont);
                    }

                    // Get a path representing the text centered on the canvas
                    g.PageUnit = GraphicsUnit.Point;
                    PointF textTopLeft = new PointF((ImageWidth - finalSize.Width) / 2,
                                                  (ImageHeight - finalSize.Height) / 2);
                    using (GraphicsPath path = new GraphicsPath())
                    {
                        path.AddString(solution, new FontFamily(GenericFontFamilies.Serif), 0,
                            bestFontSize, textTopLeft, StringFormat.GenericDefault);

                        // Render the path to the bitmap
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.FillPath(Foreground, DeformPath(path));
                        g.Flush();

                        // Send the image to the response stream in PNG format
                        Response.ContentType = "image/png";
                        using (var memoryStream = new MemoryStream())
                        {
                            bmp.Save(memoryStream, ImageFormat.Png);
                            memoryStream.WriteTo(Response.OutputStream);
                        }
                    }
                }
            }
        }
예제 #37
0
        private void DrawRectXY(int y1, int y2)
        {
            Graphics g = this.CreateGraphics();//
            Pen      p = new Pen(Color.DarkGray, 2);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.DrawLine(p, nStartX1, nStartY1, nStartX2, nStartY2 + y2);//参照位置
            g.DrawLine(p, nStartX1, nStartY1 + y1, nStartX2, nStartY2);
            p           = new Pen(Color.Green, 1);
            p.DashStyle = DashStyle.Solid;//箭头
            p.EndCap    = LineCap.ArrowAnchor;
            g.DrawLine(p, nStartX1, nStartY1, nStartX1, nStartY1 + y1);
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString("left", this.Font.FontFamily, (int)FontStyle.Bold, 10, new RectangleF(nStartX1 - 30, nStartY1 + y1 / 2, 30, 30), null);
            g.DrawPath(Pens.Black, gp);
            g.DrawLine(p, nStartX2, nStartY2, nStartX2, nStartY2 + y2);
            gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString("right", this.Font.FontFamily, (int)FontStyle.Bold, 10, new RectangleF(nStartX2 + 10, nStartY2 + y2 / 2, 30, 30), null);
            g.DrawPath(Pens.Black, gp);
            p.Dispose();
            g.Dispose();
        }
예제 #38
0
파일: form1.cs 프로젝트: yasirbhutta/docs
    //</snippet9>



    // The following code example demonstrates how to use the
    // TranslateTransform method. This example is designed to be used
    // with Windows Forms.  Create a form and paste the following code
    // into it. Call the TranslateAndTransform method in the form's
    // Paint event-handling method, passing e as PaintEventArgs.
    //<snippet10>
    private void TranslateAndTransform(PaintEventArgs e)
    {
        // Create a GraphicsPath.
        System.Drawing.Drawing2D.GraphicsPath myPath =
            new System.Drawing.Drawing2D.GraphicsPath();

        // Create a rectangle.
        RectangleF layoutRectangle =
            new RectangleF(20.0F, 20.0F, 40.0F, 50.0F);

        // Add the rectangle to the path.
        myPath.AddRectangle(layoutRectangle);

        // Add a string to the path.
        myPath.AddString("Path", this.Font.FontFamily, 2, 10.0F,
                         layoutRectangle, new StringFormat(StringFormatFlags.NoWrap));

        // Draw the path.
        e.Graphics.DrawPath(Pens.Black, myPath);

        // Call TranslateTransform and draw the path again.
        e.Graphics.TranslateTransform(10.0F, 10.0F);
        e.Graphics.DrawPath(Pens.Red, myPath);
    }
예제 #39
0
        private void DrawRectXY(int x, int y)
        {
            Graphics g = this.CreateGraphics();//

            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen p = new Pen(Color.DarkGray, 3);

            g.DrawRectangle(p, nStartX, nStartY, nStartX + nWith, nStartY + nHeight);                 //实际位置
            p.DashStyle = DashStyle.Dot;                                                              //虚线
            g.DrawRectangle(p, nStartX + x, nStartY + y, nStartX + nWith + x, nStartY + nHeight + y); //参照位置
            p           = new Pen(Color.Green, 1);
            p.DashStyle = DashStyle.Solid;                                                            //箭头
            p.EndCap    = LineCap.ArrowAnchor;
            g.DrawLine(p, nStartX + nWith + 60, nStartY, nStartX + nWith + 60, nStartY + nHeight);
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString("x", this.Font.FontFamily, (int)FontStyle.Bold, 10, new RectangleF(nStartX + nWith + 80, nStartY, 30, 30), null);
            g.DrawPath(Pens.Black, gp);
            g.DrawLine(p, nStartX, nStartY + nHeight + 60, nStartX + nWith, nStartY + nHeight + 60);
            gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString("y", this.Font.FontFamily, (int)FontStyle.Bold, 10, new RectangleF(nStartX, nStartY + nHeight + 60, 30, 30), null);
            g.DrawPath(Pens.Black, gp);
            p.Dispose();
            g.Dispose();
        }
예제 #40
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected Bitmap DrawPrivateFont_V(string drawstr, Color fontColor, Color edgeColor, bool bVertical)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new Bitmap(1, 1));
            }

            //StreamWriter stream = stream = new StreamWriter("Test.txt", false);

            //try
            //{
            //    stream = new StreamWriter("Test.txt", false);
            //}
            //catch (Exception ex)
            //{
            //    stream.Close();
            //    stream = new StreamWriter("Test.txt", false);
            //}

            string[] strName = new string[drawstr.Length];
            for (int i = 0; i < drawstr.Length; i++)
            {
                strName[i] = drawstr.Substring(i, 1);
            }

            #region [ キャンバスの大きさ予測 ]
            //大きさを計算していく。
            int nHeight = 0;
            for (int i = 0; i < strName.Length; i++)
            {
                Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue),
                                                                             System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                             System.Windows.Forms.TextFormatFlags.NoPadding);

                //stringformatは最初にやっていてもいいだろう。
                StringFormat sFormat = new StringFormat();
                sFormat.LineAlignment = StringAlignment.Center;         // 画面下部(垂直方向位置)
                sFormat.Alignment     = StringAlignment.Center;         // 画面中央(水平方向位置)


                //できるだけ正確な値を計算しておきたい...!
                Bitmap    bmpDummy   = new Bitmap(150, 150); //とりあえず150
                Graphics  gCal       = Graphics.FromImage(bmpDummy);
                Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat);
                int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                Rectangle rect = new Rectangle(0, -n余白サイズ + 2, 36, (strSize.Height + 12));

                if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~" || strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "「" || strName[i] == "」" || strName[i] == "[" || strName[i] == "]")
                {
                    nHeight += (rect正確なサイズ.Width) + 3;
                }
                else if (strName[i] == "_")
                {
                    nHeight += (rect正確なサイズ.Height) + 6;
                }
                else if (strName[i] == " ")
                {
                    nHeight += (12);
                }
                else
                {
                    nHeight += (rect正確なサイズ.Height) + 6;
                }

                //念のため解放
                bmpDummy.Dispose();
                gCal.Dispose();

                //stream.WriteLine( "文字の大きさ{0},大きさ合計{1}", ( rect正確なサイズ.Height ) + 6, nHeight );
            }
            #endregion

            Bitmap   bmpCambus = new Bitmap(36, nHeight);
            Graphics Gcambus   = Graphics.FromImage(bmpCambus);

            //キャンバス作成→1文字ずつ作成してキャンバスに描画という形がよさそうかな?
            int nNowPos = 0;
            int nAdded  = 0;
            if (this._pt < 18)
            {
                nAdded = nAdded - 2;
            }

            for (int i = 0; i < strName.Length; i++)
            {
                Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue),
                                                                             System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                             System.Windows.Forms.TextFormatFlags.NoPadding);

                //stringformatは最初にやっていてもいいだろう。
                StringFormat sFormat = new StringFormat();
                sFormat.LineAlignment = StringAlignment.Center;         // 画面下部(垂直方向位置)
                sFormat.Alignment     = StringAlignment.Near;           // 画面中央(水平方向位置)

                //できるだけ正確な値を計算しておきたい...!
                Bitmap    bmpDummy   = new Bitmap(150, 150); //とりあえず150
                Graphics  gCal       = Graphics.FromImage(bmpDummy);
                Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat);
                int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                //Bitmap bmpV = new Bitmap( 36, ( strSize.Height + 12 ) - 6 );

                Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 8) + nAdded, (rect正確なサイズ.Height) + 8);

                bmpV.MakeTransparent();
                Graphics gV = Graphics.FromImage(bmpV);
                gV.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


                Rectangle rect = new Rectangle(-3 - nAdded, -rect正確なサイズ.Y - 2, (strSize.Width + 12), (strSize.Height + 12));
                //Rectangle rect = new Rectangle( 0, -rect正確なサイズ.Y - 2, 36, rect正確なサイズ.Height + 10);

                // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                // (これをしないと、単位が違うために、小さめに描画されてしまう)
                float sizeInPixels = _font.SizeInPoints * gV.DpiY / 72;                  // 1 inch = 72 points

                System.Drawing.Drawing2D.GraphicsPath gpV = new System.Drawing.Drawing2D.GraphicsPath();
                gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat);

                // 縁取りを描画する
                Pen pV = new Pen(edgeColor, 6);
                pV.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                gV.DrawPath(pV, gpV);

                // 塗りつぶす
                Brush brV;
                {
                    brV = new SolidBrush(fontColor);
                }
                gV.FillPath(brV, gpV);

                if (brV != null)
                {
                    brV.Dispose();
                }
                brV = null;
                if (pV != null)
                {
                    pV.Dispose();
                }
                pV = null;
                if (gpV != null)
                {
                    gpV.Dispose();
                }
                gpV = null;

                int n補正  = 0;
                int nY補正 = 0;

                if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 0;
                    }
                    //nNowPos = nNowPos - 2;
                }
                else if (strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "[" || strName[i] == "]" || strName[i] == "」")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 0;
                        //nNowPos = nNowPos - 4;
                    }
                }
                else if (strName[i] == "「")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 2;
                        //nNowPos = nNowPos;
                    }
                }
                //else if( strName[ i ] == "_" )
                //    nNowPos = nNowPos + 20;
                else if (strName[i] == " ")
                {
                    nNowPos = nNowPos + 10;
                }


                //bmpV.Save( "String" + i.ToString() + ".png" );


                if (i == 0)
                {
                    nNowPos = 0;
                    Gcambus.DrawImage(bmpV, (16 - (bmpV.Size.Width / 2)) + n補正, 0);
                }
                else
                {
                    Gcambus.DrawImage(bmpV, (16 - (bmpV.Size.Width / 2)) + n補正, nNowPos);
                }
                nNowPos += bmpV.Size.Height - 3;

                if (bmpV != null)
                {
                    bmpV.Dispose();
                }
                if (gCal != null)
                {
                    gCal.Dispose();
                }

                //bmpCambus.Save( "test.png" );
                //if( this._pt < 20 )
                //    bmpCambus.Save( "test_S.png" );

                _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height);
                _ptOrigin    = new Point(6 * 2, 6 * 2);


                //stream.WriteLine( "黒無しサイズ{0},余白{1},黒あり予測サイズ{2},ポ↑ジ↓{3}",rect正確なサイズ.Height, n余白サイズ, rect正確なサイズ.Height + 8, nNowPos );
            }
            //stream.Close();

            if (Gcambus != null)
            {
                Gcambus.Dispose();
            }

            //return bmp;
            return(bmpCambus);
        }
예제 #41
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected Bitmap DrawPrivateFont_V(string drawstr, Color fontColor, Color edgeColor, bool bVertical)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new Bitmap(1, 1));
            }

            //StreamWriter stream = stream = new StreamWriter("Test.txt", false);

            //try
            //{
            //    stream = new StreamWriter("Test.txt", false);
            //}
            //catch (Exception ex)
            //{
            //    stream.Close();
            //    stream = new StreamWriter("Test.txt", false);
            //}

            string[] strName = new string[drawstr.Length];
            for (int i = 0; i < drawstr.Length; i++)
            {
                strName[i] = drawstr.Substring(i, 1);
            }

            #region [ キャンバスの大きさ予測 ]
            //大きさを計算していく。
            int nHeight = 0;
            for (int i = 0; i < strName.Length; i++)
            {
                Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue),
                                                                             System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                             System.Windows.Forms.TextFormatFlags.NoPadding);

                //stringformatは最初にやっていてもいいだろう。
                StringFormat sFormat = new StringFormat();
                sFormat.LineAlignment = StringAlignment.Center;         // 画面下部(垂直方向位置)
                sFormat.Alignment     = StringAlignment.Center;         // 画面中央(水平方向位置)


                //できるだけ正確な値を計算しておきたい...!
                Bitmap    bmpDummy   = new Bitmap(150, 150); //とりあえず150
                Graphics  gCal       = Graphics.FromImage(bmpDummy);
                Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat);
                int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                Rectangle rect = new Rectangle(0, -n余白サイズ + 2, 46, (strSize.Height + 16));

                if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~" || strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "「" || strName[i] == "」" || strName[i] == "[" || strName[i] == "]")
                {
                    nHeight += (rect正確なサイズ.Width) + 4;
                }
                else if (strName[i] == "_")
                {
                    nHeight += (rect正確なサイズ.Height) + 6;
                }
                else if (strName[i] == " ")
                {
                    nHeight += (12);
                }
                else
                {
                    nHeight += (rect正確なサイズ.Height) + 10;
                }

                //念のため解放
                bmpDummy.Dispose();
                gCal.Dispose();

                //stream.WriteLine( "文字の大きさ{0},大きさ合計{1}", ( rect正確なサイズ.Height ) + 6, nHeight );
            }
            #endregion

            Bitmap   bmpCambus = new Bitmap(46, nHeight);
            Graphics Gcambus   = Graphics.FromImage(bmpCambus);

            //キャンバス作成→1文字ずつ作成してキャンバスに描画という形がよさそうかな?
            int nNowPos  = 0;
            int nAdded   = 0;
            int nEdge補正X = 0;
            int nEdge補正Y = 0;
            if (this._pt < 18)
            {
                nAdded = nAdded - 2;
            }

            for (int i = 0; i < strName.Length; i++)
            {
                Size strSize = System.Windows.Forms.TextRenderer.MeasureText(strName[i], this._font, new Size(int.MaxValue, int.MaxValue),
                                                                             System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                             System.Windows.Forms.TextFormatFlags.NoPadding);

                //stringformatは最初にやっていてもいいだろう。
                StringFormat sFormat = new StringFormat();
                sFormat.LineAlignment = StringAlignment.Center; // 画面下部(垂直方向位置)
                sFormat.Alignment     = StringAlignment.Near;   // 画面中央(水平方向位置)

                //できるだけ正確な値を計算しておきたい...!
                Bitmap    bmpDummy   = new Bitmap(150, 150); //とりあえず150
                Graphics  gCal       = Graphics.FromImage(bmpDummy);
                Rectangle rect正確なサイズ = this.MeasureStringPrecisely(gCal, strName[i], this._font, strSize, sFormat);
                int       n余白サイズ     = strSize.Height - rect正確なサイズ.Height;

                //Bitmap bmpV = new Bitmap( 36, ( strSize.Height + 12 ) - 6 );

                Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 12) + nAdded, (rect正確なサイズ.Height) + 12);

                bmpV.MakeTransparent();
                Graphics gV = Graphics.FromImage(bmpV);
                gV.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


                if (strName[i].In(TJAPlayer3.Skin.SongSelect_CorrectionX_Chara))
                {
                    nEdge補正X = TJAPlayer3.Skin.SongSelect_CorrectionX_Chara_Value;
                }
                else
                {
                    nEdge補正X = 0;
                }
                if (strName[i].In(TJAPlayer3.Skin.SongSelect_CorrectionY_Chara))
                {
                    nEdge補正Y = TJAPlayer3.Skin.SongSelect_CorrectionY_Chara_Value;
                }
                else
                {
                    nEdge補正Y = 0;
                }
                //X座標、Y座標それぞれについて、SkinConfig内でズレを直したい文字を , で区切って列挙して、
                //補正値を記入することで、特定のそれらの文字について一括で座標をずらす。
                //現時点では補正値をX,Y各座標について1個ずつしか取れない(複数対1)ので、
                //文字を列挙して、同じ数だけそれぞれの文字の補正値を記入できるような枠組をつくりたい。(20181205 rhimm)

                Rectangle rect = new Rectangle(-3 - nAdded + (nEdge補正X * (int)_pt / 100), -rect正確なサイズ.Y - 2 + (nEdge補正Y * (int)_pt / 100), (strSize.Width + 12), (strSize.Height + 11));
                //Rectangle rect = new Rectangle( 0, -rect正確なサイズ.Y - 2, 36, rect正確なサイズ.Height + 10);

                // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                // (これをしないと、単位が違うために、小さめに描画されてしまう)
                float sizeInPixels = _font.SizeInPoints * gV.DpiY / 72;  // 1 inch = 72 points

                System.Drawing.Drawing2D.GraphicsPath gpV = new System.Drawing.Drawing2D.GraphicsPath();
                gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat);

                // 縁取りを描画する
                //int nEdgePt = (_pt / 3); // 縁取りをフォントサイズ基準に変更
                int nEdgePt = (20 * (int)_pt / TJAPlayer3.Skin.Font_Edge_Ratio_Vertical); // SkinConfigにて設定可能に(rhimm)
                Pen pV      = new Pen(edgeColor, nEdgePt);
                pV.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                gV.DrawPath(pV, gpV);

                // 塗りつぶす
                Brush brV;
                {
                    brV = new SolidBrush(fontColor);
                }
                gV.FillPath(brV, gpV);

                if (brV != null)
                {
                    brV.Dispose();
                }
                brV = null;
                if (pV != null)
                {
                    pV.Dispose();
                }
                pV = null;
                if (gpV != null)
                {
                    gpV.Dispose();
                }
                gpV = null;
                if (gV != null)
                {
                    gV.Dispose();
                }
                gV = null;

                int n補正  = 0;
                int nY補正 = 0;

                if (strName[i] == "ー" || strName[i] == "-" || strName[i] == "~")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 0;
                    }
                    //nNowPos = nNowPos - 2;
                }
                else if (strName[i] == "<" || strName[i] == ">" || strName[i] == "(" || strName[i] == ")" || strName[i] == "[" || strName[i] == "]" || strName[i] == "」" || strName[i] == ")" || strName[i] == "』")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 0;
                        //nNowPos = nNowPos - 4;
                    }
                }
                else if (strName[i] == "「" || strName[i] == "(" || strName[i] == "『")
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    n補正 = 2;
                    if (this._pt < 20)
                    {
                        n補正 = 2;
                        //nNowPos = nNowPos;
                    }
                }
                else if (strName[i] == "・")
                {
                    n補正 = -8;
                    if (this._pt < 20)
                    {
                        n補正 = -8;
                        //nNowPos = nNowPos;
                    }
                }
                else if (strName[i] == ".")
                {
                    n補正 = 8;
                    if (this._pt < 20)
                    {
                        n補正 = 8;
                        //nNowPos = nNowPos;
                    }
                }
                else if (strName[i].In(TJAPlayer3.Skin.SongSelect_Rotate_Chara))
                {
                    bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone);
                }
                //個別の文字に関して、カンマで区切ってSkinConfigに記入したものを回転させる(20181205 rhimm)


                //else if( strName[ i ] == "_" )
                //    nNowPos = nNowPos + 20;
                else if (strName[i] == " ")
                {
                    nNowPos = nNowPos + 10;
                }


                //bmpV.Save( "String" + i.ToString() + ".png" );


                if (i == 0)
                {
                    nNowPos = 4;
                }
                Gcambus.DrawImage(bmpV, (bmpCambus.Width / 2) - (bmpV.Width / 2) + n補正, nNowPos + nY補正);
                nNowPos += bmpV.Size.Height - 6;

                if (bmpV != null)
                {
                    bmpV.Dispose();
                }
                bmpV = null;
                if (gCal != null)
                {
                    gCal.Dispose();
                }
                gCal = null;

                //bmpCambus.Save( "test.png" );
                //if( this._pt < 20 )
                //    bmpCambus.Save( "test_S.png" );

                _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height);
                _ptOrigin    = new Point(6 * 2, 6 * 2);


                //stream.WriteLine( "黒無しサイズ{0},余白{1},黒あり予測サイズ{2},ポ↑ジ↓{3}",rect正確なサイズ.Height, n余白サイズ, rect正確なサイズ.Height + 8, nNowPos );
            }
            //stream.Close();

            if (Gcambus != null)
            {
                Gcambus.Dispose();
            }

            //return bmp;
            return(bmpCambus);
        }
예제 #42
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        protected Bitmap DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                if (drawstr != "")
                {
                    Trace.TraceWarning("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                }
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new Bitmap(1, 1));
            }
            bool bEdge      = ((drawmode & DrawMode.Edge) == DrawMode.Edge);
            bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation);

            // 縁取りの縁のサイズは、とりあえずフォントの大きさの1/4とする
            //int nEdgePt = (bEdge)? _pt / 4 : 0;
            //int nEdgePt = (bEdge) ? (_pt / 3) : 0; // 縁取りが少なすぎるという意見が多かったため変更。 (AioiLight)
            int nEdgePt = (bEdge) ? (10 * (int)_pt / TJAPlayer3.Skin.Font_Edge_Ratio) : 0; //SkinConfigにて設定可能に(rhimm)

            // 描画サイズを測定する
            Size stringSize = System.Windows.Forms.TextRenderer.MeasureText(drawstr, this._font, new Size(int.MaxValue, int.MaxValue),
                                                                            System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                            System.Windows.Forms.TextFormatFlags.NoPadding
                                                                            );

            stringSize.Width += 10; //2015.04.01 kairera0467 ROTTERDAM NATIONの描画サイズがうまくいかんので。

            //取得した描画サイズを基に、描画先のbitmapを作成する
            Bitmap bmp = new Bitmap(stringSize.Width + nEdgePt * 2, stringSize.Height + nEdgePt * 2);

            bmp.MakeTransparent();
            Graphics g = Graphics.FromImage(bmp);

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

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Far;      // 画面下部(垂直方向位置)
            sf.Alignment     = StringAlignment.Center;   // 画面中央(水平方向位置)
            sf.FormatFlags   = StringFormatFlags.NoWrap; // どんなに長くて単語の区切りが良くても改行しない (AioiLight)
            sf.Trimming      = StringTrimming.None;      // どんなに長くてもトリミングしない (AioiLight)
            // レイアウト枠
            Rectangle r = new Rectangle(0, 0, stringSize.Width + nEdgePt * 2 + (TJAPlayer3.Skin.Text_Correction_X * stringSize.Width / 100), stringSize.Height + nEdgePt * 2 + (TJAPlayer3.Skin.Text_Correction_Y * stringSize.Height / 100));

            if (bEdge)                  // 縁取り有りの描画
            {
                // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                // (これをしないと、単位が違うために、小さめに描画されてしまう)
                float sizeInPixels = _font.SizeInPoints * g.DpiY / 72;                  // 1 inch = 72 points

                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf);

                // 縁取りを描画する
                Pen p = new Pen(edgeColor, nEdgePt);
                p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                g.DrawPath(p, gp);

                // 塗りつぶす
                Brush br;
                if (bGradation)
                {
                    br = new LinearGradientBrush(r, gradationTopColor, gradationBottomColor, LinearGradientMode.Vertical);
                }
                else
                {
                    br = new SolidBrush(fontColor);
                }
                g.FillPath(br, gp);

                if (br != null)
                {
                    br.Dispose();
                }
                br = null;
                if (p != null)
                {
                    p.Dispose();
                }
                p = null;
                if (gp != null)
                {
                    gp.Dispose();
                }
                gp = null;
            }
            else
            {
                // 縁取りなしの描画
                System.Windows.Forms.TextRenderer.DrawText(g, drawstr, _font, new Point(0, 0), fontColor);
            }
#if debug表示
            g.DrawRectangle(new Pen(Color.White, 1), new Rectangle(1, 1, stringSize.Width - 1, stringSize.Height - 1));
            g.DrawRectangle(new Pen(Color.Green, 1), new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1));
#endif
            _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height);
            _ptOrigin    = new Point(nEdgePt * 2, nEdgePt * 2);


            #region [ リソースを解放する ]
            if (sf != null)
            {
                sf.Dispose();
            }
            sf = null;
            if (g != null)
            {
                g.Dispose();
            }
            g = null;
            #endregion

            return(bmp);
        }
예제 #43
0
        /// <summary>
        /// Esta función se encarga de cortar la imagen y preparar su numeración, cada trozo lo almacena
        /// en la lista "tmpImagenes"
        /// </summary>
        /// <param name="Columnas">Columnas que tiene el tablero</param>
        /// <param name="Filas">Filas que tiene el tablero</param>
        /// <param name="Height">Altura de cada celda</param>
        /// <param name="Width">Anchura de cada celda</param>
        /// <returns>Retorna true en caso de haber podido preparar la imagen, y false si por cualquier error no se ha podido preparar</returns>
        public bool Preparar_Imagen(int Columnas, int Filas, int Height, int Width)
        {
            tmpImagenes.Clear();
            bool tmpResult = false;

            try
            {
                if (File.Exists(this.Ruta) == true)
                {
                    Image PicMain = null;
                    PicMain = Image.FromFile(this.Ruta);
                    //Comprovamos si la imagen es más pequeña que el tablero, si lo es, la redimensionamos antes de cortarla
                    if ((PicMain.Width < (Width * Columnas)) || (PicMain.Height < (Height * Filas)))
                    {
                        PicMain = this.Set_Minimum_Size(PicMain, new Size(Columnas * Width, Filas * Height));
                    }
                    int       TamanyoTrozoWidth   = PicMain.Width / Columnas;
                    int       TamanyoTrozoHeight  = PicMain.Height / Filas;
                    Rectangle Rectangulo_Destino  = new Rectangle(0, 0, Width, Height);
                    Bitmap    bmpDest             = null;
                    Graphics  tmpGraficos_Dibujo  = null;
                    Graphics  tmpGraficos_Numeros = null;
                    Rectangle Rectangulo_Original = new Rectangle();
                    int       tmpColumnaActual    = 0;
                    int       Pixel_X             = 0;
                    int       Pixel_Y             = 0;
                    Pixel_X = 0;
                    Pixel_Y = 0;
                    Font tmpFontBack = new Font("Comic Sanz", 15F, FontStyle.Bold, GraphicsUnit.Pixel);
                    for (int I = 0; I < (Columnas * Filas); I++)
                    {
                        Rectangulo_Original = new Rectangle(Pixel_X, Pixel_Y, TamanyoTrozoWidth, TamanyoTrozoHeight);
                        bmpDest             = new Bitmap(TamanyoTrozoWidth, TamanyoTrozoHeight);
                        tmpGraficos_Dibujo  = Graphics.FromImage(bmpDest);
                        tmpGraficos_Dibujo.DrawImage(PicMain, Rectangulo_Destino, Rectangulo_Original, GraphicsUnit.Pixel);
                        tmpGraficos_Numeros = Graphics.FromImage(bmpDest);
                        //Insertamos el número dentro del trozo de imagen para numerarla
                        if (this.NumerarImagenes == true)
                        {
                            GraphicsPath Lapiz = new System.Drawing.Drawing2D.GraphicsPath();
                            Lapiz.AddString((I + 1).ToString(), tmpFontBack.FontFamily, Convert.ToInt32(FontStyle.Bold), 20F, new Point(0, 0), StringFormat.GenericTypographic);
                            tmpGraficos_Numeros.FillPath(Brushes.White, Lapiz);
                            tmpGraficos_Numeros.DrawPath(Pens.Black, Lapiz);
                            tmpGraficos_Numeros.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                            tmpGraficos_Numeros.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        }
                        tmpImagenes.Add(bmpDest);
                        tmpColumnaActual += 1;
                        Pixel_X          += TamanyoTrozoWidth;
                        if (tmpColumnaActual >= Columnas)
                        {
                            tmpColumnaActual = 0;
                            Pixel_X          = 0;
                            Pixel_Y         += TamanyoTrozoHeight;
                        }
                    }
                    tmpResult = true;
                }
                return(tmpResult);
            }
            catch
            {
                return(tmpResult);
            }
        }
예제 #44
0
        /// <summary>
        /// 文字列を描画したテクスチャを返す(メイン処理)
        /// </summary>
        /// <param name="rectDrawn">描画された領域</param>
        /// <param name="ptOrigin">描画文字列</param>
        /// <param name="drawstr">描画文字列</param>
        /// <param name="drawmode">描画モード</param>
        /// <param name="fontColor">描画色</param>
        /// <param name="edgeColor">縁取色</param>
        /// <param name="gradationTopColor">グラデーション 上側の色</param>
        /// <param name="gradationBottomColor">グラデーション 下側の色</param>
        /// <returns>描画済テクスチャ</returns>
        public Bitmap DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor, bool bEdgeGradation)
        {
            if (this._fontfamily == null || drawstr == null || drawstr == "")
            {
                // nullを返すと、その後bmp→texture処理や、textureのサイズを見て__の処理で全部例外が発生することになる。
                // それは非常に面倒なので、最小限のbitmapを返してしまう。
                // まずはこの仕様で進めますが、問題有れば(上位側からエラー検出が必要であれば)例外を出したりエラー状態であるプロパティを定義するなり検討します。
                Trace.TraceError("DrawPrivateFont()の入力不正。最小値のbitmapを返します。");
                _rectStrings = new Rectangle(0, 0, 0, 0);
                _ptOrigin    = new Point(0, 0);
                return(new Bitmap(1, 1));
            }
            bool bEdge      = ((drawmode & DrawMode.Edge) == DrawMode.Edge);
            bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation);

            // 縁取りの縁のサイズは、とりあえずフォントの大きさの1/4とする
            // Changed to 1/6 as 1/4 is too thick for new Black-White Style
            int nEdgePt = (bEdge) ? _pt / 6 : 0;

            // 描画サイズを測定する
            Size stringSize = System.Windows.Forms.TextRenderer.MeasureText(drawstr, this._font, new Size(int.MaxValue, int.MaxValue),
                                                                            System.Windows.Forms.TextFormatFlags.NoPrefix |
                                                                            System.Windows.Forms.TextFormatFlags.NoPadding
                                                                            );

            //取得した描画サイズを基に、描画先のbitmapを作成する
            int    l_width = (int)(stringSize.Width * 1.05f);          //A constant proportion of 5% buffer should avoid the issue of text truncation
            Bitmap bmp     = new Bitmap(l_width, stringSize.Height + nEdgePt * 2);

            bmp.MakeTransparent();
            Graphics g = Graphics.FromImage(bmp);

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

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Far;             // 画面下部(垂直方向位置)
            sf.Alignment     = StringAlignment.Near;            // 画面中央(水平方向位置)//Changed to Left (Near) of Texture rect

            // レイアウト枠
            Rectangle r = new Rectangle(0, 0, l_width, stringSize.Height + nEdgePt * 2);

            //r = new Rectangle( 0, 0, l_width + nEdgePt*2, stringSize.Height + nEdgePt * 2 ); // 2016.06.12 kairera0467 改行防止

            if (bEdge && bEdgeGradation)                // 縁取り有りの描画
            {
                // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する
                // (これをしないと、単位が違うために、小さめに描画されてしまう)
                float sizeInPixels = _font.SizeInPoints * g.DpiY / 72;                  // 1 inch = 72 points

                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf);

                // 縁取りを描画する
                Brush br縁;
                br縁 = new LinearGradientBrush(r, gradationTopColor, gradationBottomColor, LinearGradientMode.Vertical);
                Pen p = new Pen(br縁, nEdgePt);
                p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                g.DrawPath(p, gp);

                // 塗りつぶす
                Brush br;
                br = new SolidBrush(fontColor);
                g.FillPath(br, gp);

                if (br != null)
                {
                    br.Dispose();
                }
                br = null;
                if (p != null)
                {
                    p.Dispose();
                }
                p = null;
                if (gp != null)
                {
                    gp.Dispose();
                }
                gp = null;
            }
            else
            {
                // 縁取りなしの描画
                System.Windows.Forms.TextRenderer.DrawText(g, drawstr, _font, new Point(0, 0), fontColor);
            }
#if debug表示
            g.DrawRectangle(new Pen(Color.White, 1), new Rectangle(1, 1, stringSize.Width - 1, stringSize.Height - 1));
            g.DrawRectangle(new Pen(Color.Green, 1), new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1));
#endif
            _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height);
            _ptOrigin    = new Point(nEdgePt * 2, nEdgePt * 2);


            #region [ リソースを解放する ]
            if (sf != null)
            {
                sf.Dispose();
            }
            sf = null;
            if (g != null)
            {
                g.Dispose();
            }
            g = null;
            #endregion

            return(bmp);
        }
예제 #45
0
        private static void DrawLegenda(Graphics monitorGraphics, ScaledScreen scaledScreen, DesktopImage imageData, Form controlerForm)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            //System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            //System.Drawing.Pen yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            //System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;


            float textScale = scaledScreen.Scale;

            Rectangle legendaRect = GetLegendaRect(monitorGraphics, scaledScreen);


            // search for date taken
            DateTime dateTaken = DateTime.Now;

            //String tags = imageData.Image.Tag;


            foreach (PropertyItem propItem in imageData.Image.PropertyItems)
            {
                if (propItem.Id == PropertyTagExifDTOrig)
                {
                    string dateTakenString = dateRegex.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
                    dateTaken = DateTime.Parse(dateTakenString);
                }
            }

            // test for controler form
            if (controlerForm != null)
            {
                // update start
                controlerForm.Tag = imageData;
                controlerForm.Refresh();
                //UpdateDisplay(imageData);
                // draw each of the invisible controls
                foreach (Label label in controlerForm.Controls)
                {
                    // check "invisible" each element on the form
                    if (!label.Visible)
                    {
                        Image image  = label.Image;
                        int   x      = label.Left + controlerForm.Left;
                        int   y      = label.Top + controlerForm.Top;
                        int   width  = label.Width;
                        int   height = label.Height;

                        monitorGraphics.DrawImage(image, x, y, width, height);
                    }
                }
            }

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(imageData.Filename,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);
            path.AddString(imageData.DisplayFolder,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(25 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(20 * textScale), legendaRect.Width, (int)(25 * textScale)),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", imageData.Image.Width, imageData.Image.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(16 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(50 * textScale), legendaRect.Width, (int)(16 * textScale)),
                           stringFormat);



            path.AddString(dateTaken.ToString("dd-MM-yyyy hh:mm"),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(70 * textScale), legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);


            //monitorGraphics.DrawPath(redPen, path);
            //monitorGraphics.DrawPath(yellowPen, path);
            //monitorGraphics.FillPath(brush, path);

            Color textColor = Color.FromArgb(255, 255, 255);
            Color glowColor = Color.FromArgb(0, 0, 0);
            //Color textColor = Color.FromArgb(0, 0, 0);
            //Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #46
0
        private static void DrawLegenda_orig(Graphics monitorGraphics, ScaledScreen scaledScreen, DesktopImage imageData)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            //System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            //System.Drawing.Pen yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            //System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            float textScale = scaledScreen.Scale;

            Rectangle legendaRect = new Rectangle(
                (int)monitorGraphics.VisibleClipBounds.Width - (int)(400 * textScale)
                - scaledScreen.TaskbarRightWidth,
                (int)monitorGraphics.VisibleClipBounds.Height - (int)(100 * textScale)
                - scaledScreen.TaskbarBottomHeight
                ,
                (int)(400 * textScale),
                (int)(100 * textScale));

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(imageData.Filename,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);
            path.AddString(imageData.DisplayFolder,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(25 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(20 * textScale), legendaRect.Width, (int)(25 * textScale)),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", imageData.Image.Width, imageData.Image.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(16 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(50 * textScale), legendaRect.Width, (int)(16 * textScale)),
                           stringFormat);

            // search for date taken
            DateTime dateTaken = DateTime.Now;

            foreach (PropertyItem propItem in imageData.Image.PropertyItems)
            {
                if (propItem.Id == PropertyTagExifDTOrig)
                {
                    string dateTakenString = dateRegex.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
                    dateTaken = DateTime.Parse(dateTakenString);
                }
            }

            path.AddString(dateTaken.ToString("dd-MM-yyyy hh:mm"),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(70 * textScale), legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);


            //monitorGraphics.DrawPath(redPen, path);
            //monitorGraphics.DrawPath(yellowPen, path);
            //monitorGraphics.FillPath(brush, path);

            Color textColor = Color.FromArgb(255, 255, 255);
            Color glowColor = Color.FromArgb(0, 0, 0);
            //Color textColor = Color.FromArgb(0, 0, 0);
            //Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #47
0
        public static void DrawText(Font font, StringFormat sf, System.Drawing.Drawing2D.GraphicsPath path, StringBuilder sb, bool isItalic, bool isBold, bool isUnderline, float left, float top, ref bool newLine, float leftMargin, ref int pathPointsStart)
        {
            var next = new PointF(left, top);

            if (path.PointCount > 0)
            {
                int k = 0;

                PointF[] list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                for (int i = list.Length - 1; i >= 0; i--)
                {
                    if (list[i].X > next.X)
                    {
                        next.X = list[i].X;
                    }
                    k++;
                    if (k > 60)
                    {
                        break;
                    }
                    if (i <= pathPointsStart && pathPointsStart != -1)
                    {
                        break;
                    }
                }
            }

            if (newLine)
            {
                next.X          = leftMargin;
                newLine         = false;
                pathPointsStart = path.PointCount;
            }

            var fontStyle = FontStyle.Regular;

            if (isItalic && isBold && isUnderline)
            {
                fontStyle = FontStyle.Italic | FontStyle.Bold | FontStyle.Underline;
            }
            else if (isItalic && isBold)
            {
                fontStyle = FontStyle.Italic | FontStyle.Bold;
            }
            else if (isItalic && isUnderline)
            {
                fontStyle = FontStyle.Italic | FontStyle.Underline;
            }
            else if (isUnderline && isBold)
            {
                fontStyle = FontStyle.Underline | FontStyle.Bold;
            }
            else if (isItalic)
            {
                fontStyle = FontStyle.Italic;
            }
            else if (isBold)
            {
                fontStyle = FontStyle.Bold;
            }
            else if (isUnderline)
            {
                fontStyle = FontStyle.Underline;
            }
            try
            {
                path.AddString(sb.ToString(), font.FontFamily, (int)fontStyle, font.Size, next, sf);
            }
            catch
            {
                fontStyle = FontStyle.Regular;
                try
                {
                    path.AddString(sb.ToString(), font.FontFamily, (int)fontStyle, font.Size, next, sf);
                }
                catch
                {
                    path.AddString(sb.ToString(), new FontFamily("Arial"), (int)fontStyle, font.Size, next, sf);
                }
            }
            sb.Length = 0;
        }
예제 #48
0
        public void Form1_Paint(object sender, PaintEventArgs e)
        {
            //////    // Create a graphics path and add an ellipse.
            //////    GraphicsPath myPath = new GraphicsPath();
            //////    Rectangle rect = new Rectangle(100, 20, 100, 50);
            //////    myPath.AddRectangle(rect);
            //////    // Get the path's array of points.
            //////    PointF[] myPathPointArray = myPath.PathPoints;
            //////    // Create a path gradient brush.
            //////    PathGradientBrush myPGBrush = new
            //////    PathGradientBrush(myPathPointArray);
            //////    // Set the color span.
            //////    myPGBrush.CenterColor = Color.Green;
            //////    Color[] mySurroundColor = { Color.Blue };
            //////    myPGBrush.SurroundColors = mySurroundColor;
            //////    // Draw the brush to the screen prior to transformation.
            //////    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
            //////    // Apply the rotate transform to the brush.
            //////    myPGBrush.RotateTransform(a, MatrixOrder.Append);
            //////    // Draw the brush to the screen again after applying the
            //////    // transform.
            //////    e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
            GraphicsPath path = new GraphicsPath(); int Wi = 0; int Hi = 0;

            path.AddEllipse(160, 70, 150, 70);

            // Use the path to construct a brush.
            PathGradientBrush pthGrBrush = new PathGradientBrush(path);

            // Set the color at the center of the path to blue.
            pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);
            //pthGrBrush.FocusScales = new PointF(40, 40);
            // Set the color along the entire boundary
            // of the path to aqua.
            Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
            pthGrBrush.SurroundColors = colors;


            pthGrBrush.RotateTransform(a);

            for (int t = 0; t < 100; t++)
            {
                PointF wq = new PointF(); wq.X = 40; wq.Y = 40; pthGrBrush.TranslateTransform(1, 1); e.Graphics.FillRectangle(pthGrBrush, 0, 0, 700, 700); Invalidate();
            }


            Bitmap bm = new Bitmap(img.Width, img.Height);

            if (a <= 90)
            {
                Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 90 && a <= 180)
            {
                Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 180 && a <= 270)
            {
                Wi = (int)(bm.Width * -Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * -Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360));
            }
            else if (a > 270 && a <= 360)
            {
                Wi = (int)(bm.Width * Math.Cos(2 * Math.PI * a / 360) + bm.Height * -Math.Sin(2 * Math.PI * a / 360));
                Hi = (int)(bm.Height * Math.Cos(2 * Math.PI * a / 360) + bm.Width * -Math.Sin(2 * Math.PI * a / 360));
            }
            Bitmap b = new Bitmap(Wi, Hi);



            g.TranslateTransform(Wi / 2, Hi / 2);
            g.RotateTransform(a);
            g.TranslateTransform(-img.Width / 2, -img.Height / 2);

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(img, 0, 0);
            e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
            e.Graphics.DrawImage(b, -b.Width / 2, -b.Height / 2);

            Create the string to draw on the form.
            string text = "Roma prodakshen";

            // Create a GraphicsPath.
            System.Drawing.Drawing2D.GraphicsPath path =
                new System.Drawing.Drawing2D.GraphicsPath();

            // Add the string to the path; declare the font, font style, size, and
            // vertical format for the string.
            path.AddString(text, this.Font.FontFamily, 1, 15,
                           new PointF(100.0F, 50.0F),
                           new StringFormat(StringFormatFlags.DirectionVertical));

            // Declare a matrix that will be used to rotate the text.
            System.Drawing.Drawing2D.Matrix rotateMatrix =
                new System.Drawing.Drawing2D.Matrix();

            // Set the rotation angle and starting point for the text.
            rotateMatrix.RotateAt(a, new PointF(200.0F, 50.0F));

            // Transform the text with the matrix.
            path.Transform(rotateMatrix);

            // Set the SmoothingMode to high quality for best readability.
            e.Graphics.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // Fill in the path to draw the string.
            e.Graphics.FillPath(Brushes.GreenYellow, path);

            // Dispose of the path.
            path.Dispose();
        }
 public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath path)
 {
     path.AddString(text, font.FontFamily, (int)font.Style, font.Size, pos, System.Drawing.StringFormat.GenericDefault);
 }
예제 #50
0
        private void drawing()//描画メソッド
        {
            if (Bordering_enable == true && pictureBox1.Image != null)
            {
                pictureBox1.Image.Dispose();//開放
            }
            if (pictureBox1.Image != null)
            {
                pictureBox1.Image = null;
            }

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(dt, new FontFamily(font),
                           (int)fstyle, font_size, new Point(x, y),
                           StringFormat.GenericDefault);


            if (Bordering_enable == true)
            {
                //フォントオブジェクトの作成
                Font fnt = new Font(font, font_size);

                //描画先とするImageオブジェクトを作成する
                Bitmap canvas = new Bitmap(pictureBox1.Width, pictureBox1.Height);

                //ImageオブジェクトのGraphicsオブジェクトを作成する
                Graphics g = Graphics.FromImage(canvas);


                //GraphicsPathオブジェクトの作成
                System.Drawing.Drawing2D.GraphicsPath gp =
                    new System.Drawing.Drawing2D.GraphicsPath();
                //GraphicsPathに文字列を追加する
                FontFamily ff = new FontFamily(font);
                gp.AddString(dt, ff, (int)fstyle, font_size,
                             new Point(x, y), StringFormat.GenericDefault);

                //SmoothingModeを指定する
                g.SmoothingMode = smmode;

                //文字列の中を塗りつぶす
                //g.FillPath(Brushes.White, gp);
                //文字列の縁を描画する
                Pen p = new Pen(pen_color, pen_size);
                g.DrawPath(p, gp);

                //スケーリング(文字列の幅に合わせてフォームサイズ変更)
                SizeF stringSize = g.MeasureString(dt, fnt, 4096, StringFormat.GenericDefault); //幅4096として計算
                //SizeF stringSize = g.MeasureString(dt, fnt, 4096, StringFormat.GenericDefault);//変更前
                this.Size = new Size((int)stringSize.Width + x, (int)stringSize.Height + y);    //オフセットx,y
                w         = (int)stringSize.Width;
                h         = (int)stringSize.Height;

                //リソースを解放する
                ff.Dispose();
                fnt.Dispose();
                g.Dispose();

                //PictureBox1に表示する
                pictureBox1.Image = canvas;
            }

            this.Region = new Region(path);//フォーム変形
        }
예제 #51
0
    /*public static void generateCaptcha(HttpContext context, int length, randomType type, int width, int height, System.Drawing.Color top_color, System.Drawing.Color bottom_color, System.Drawing.Color text_color)
     * {
     *  System.Drawing.Drawing2D.HatchBrush hatchBrush = null;
     *
     *  string embedded_string = commonFunctions.generateRandom(length, type);
     *
     *  commonVariables.SetSessionVariable("vCode", commonEncryption.encrypting(embedded_string));
     *
     *  char[] char_array = null;
     *
     *  char_array = new char[embedded_string.Length + embedded_string.Length];
     *
     *  for (int int_count = 0; int_count < embedded_string.Length; int_count++)
     *  {
     *      char_array[int_count + int_count] = embedded_string[int_count];
     *      char_array[int_count + int_count + 1] = " "[0];
     *  }
     *
     *  //Captcha String
     *  System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily("Comic Sans MS");
     *  // -  Generate Random
     *  //int randomsize = 5;
     *  Random random = new Random(DateTime.Now.Millisecond);
     *
     *  // Create a new 32-bit bitmap image.
     *  using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
     *  {
     *      // Create a graphics object for drawing.
     *      using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
     *      {
     *          g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
     *          System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);
     *
     *          // Fill in the background.
     *          using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, top_color, bottom_color))
     *          {
     *              g.FillRectangle(hatchBrush, rect);
     *
     *              // Set up the text font.
     *              System.Drawing.SizeF size = default(System.Drawing.SizeF);
     *              float fontSize = rect.Height + 25;
     *              System.Drawing.Font font = null;
     *              System.Drawing.StringFormat format = new System.Drawing.StringFormat();
     *              format.Alignment = System.Drawing.StringAlignment.Center;
     *              format.LineAlignment = System.Drawing.StringAlignment.Center;
     *
     *              // Adjust the font size until the text fits within the image.
     *              do
     *              {
     *                  fontSize -= 5;
     *                  font = new System.Drawing.Font(fontFamily, fontSize, System.Drawing.FontStyle.Bold);
     *                  size = g.MeasureString(new string(char_array), font, new System.Drawing.SizeF(width, height), format);
     *              } while (size.Width > rect.Width);
     *
     *              // Create a path using the text and warp it randomly.
     *              System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     *              path.AddString(new string(char_array), font.FontFamily, Convert.ToInt32(font.Style), font.Size, rect, format);
     *
     *              float v = 6f;
     *              System.Drawing.PointF[] points = {
     *                                                   new System.Drawing.PointF(random.Next(rect.Width) / v, random.Next(rect.Height) / v),
     *                                                   new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v),
     *                                                   new System.Drawing.PointF(random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v),
     *                                                   new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v)
     *                                               };
     *              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.
     *              using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal, text_color, text_color))
     *              {
     *                  g.FillPath(hatchBrush, path);
     *              }
     *
     *              font.Dispose();
     *          }
     *      }
     *
     *      context.Response.ContentType = "image/png";
     *      bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
     *  }
     * }*/
    public static string generateCaptcha(HttpContext context, int length, randomType type, int width, int height, System.Drawing.Color top_color, System.Drawing.Color bottom_color, System.Drawing.Color text_color)
    {
        System.Drawing.Drawing2D.HatchBrush hatchBrush = null;

        string strCode = commonFunctions.generateRandom(length, type);

        commonVariables.SetSessionVariable("vCode", commonEncryption.encrypting(strCode));

        string strProcessRemark   = "CommonFunction:" + strCode;
        int    intProcessSerialId = 0;

        intProcessSerialId += 1;
        commonAuditTrail.appendLog("system", "CommonFunction", "ParameterValidation", "DataBaseManager.DLL", "", "", "", "", strProcessRemark, Convert.ToString(intProcessSerialId), "", true);


        //context.Session["vCode"] = commonEncryption.encrypting(strCode);

        char[] char_array = null;

        char_array = new char[strCode.Length + strCode.Length];

        for (int int_count = 0; int_count < strCode.Length; int_count++)
        {
            char_array[int_count + int_count]     = strCode[int_count];
            char_array[int_count + int_count + 1] = " "[0];
        }

        //Captcha String
        System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily("Comic Sans MS");
        // -  Generate Random
        //int randomsize = 5;
        Random random = new Random(DateTime.Now.Millisecond);

        // Create a new 32-bit bitmap image.
        using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
        {
            // Create a graphics object for drawing.
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height);

                // Fill in the background.
                using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, top_color, bottom_color))
                {
                    g.FillRectangle(hatchBrush, rect);

                    // Set up the text font.
                    System.Drawing.SizeF size          = default(System.Drawing.SizeF);
                    float fontSize                     = rect.Height + 25;
                    System.Drawing.Font         font   = null;
                    System.Drawing.StringFormat format = new System.Drawing.StringFormat();
                    format.Alignment     = System.Drawing.StringAlignment.Center;
                    format.LineAlignment = System.Drawing.StringAlignment.Center;

                    // Adjust the font size until the text fits within the image.
                    do
                    {
                        fontSize -= 5;
                        font      = new System.Drawing.Font(fontFamily, fontSize, System.Drawing.FontStyle.Bold);
                        size      = g.MeasureString(new string(char_array), font, new System.Drawing.SizeF(width, height), format);
                    } while (size.Width > rect.Width);

                    // Create a path using the text and warp it randomly.
                    System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddString(new string(char_array), font.FontFamily, Convert.ToInt32(font.Style), font.Size, rect, format);

                    float v = 6f;
                    System.Drawing.PointF[] points =
                    {
                        new System.Drawing.PointF(random.Next(rect.Width) / v,              random.Next(rect.Height) / v),
                        new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v),
                        new System.Drawing.PointF(random.Next(rect.Width) / v,              rect.Height - random.Next(rect.Height) / v),
                        new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v)
                    };
                    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.
                    using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal, text_color, text_color))
                    {
                        g.FillPath(hatchBrush, path);
                    }

                    font.Dispose();
                }
            }

            context.Response.ContentType = "image/png";
            bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
            return(strCode);
        }
    }