private void ResimOlustur(int genislik, int yukseklik) { Bitmap bitmap = new Bitmap(genislik, yukseklik, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, genislik, yukseklik); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(System.Drawing.FontFamily.GenericSerif.Name, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.Image = bitmap; }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.CompositingMode = CompositingMode.SourceOver; GraphicsPath stroke = new GraphicsPath(); stroke.AddString(this.Text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); string tmp = this.Text; while (stroke.GetBounds().Width > this.Width - 8) { tmp = tmp.Substring(0, tmp.Length - 1); stroke = new GraphicsPath(); stroke.AddString(tmp + "...", this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); } RectangleF bounds = stroke.GetBounds(); Matrix translationMatrix = new Matrix(); if (this.TextAlign == ContentAlignment.TopRight || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.BottomRight) { translationMatrix.Translate(this.Width - bounds.Width - 8, 0); } else if (this.TextAlign == ContentAlignment.TopCenter || this.TextAlign == ContentAlignment.MiddleCenter || this.TextAlign == ContentAlignment.BottomCenter) { translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, 0); } if (this.TextAlign == ContentAlignment.MiddleLeft || this.TextAlign == ContentAlignment.MiddleRight || this.TextAlign == ContentAlignment.MiddleCenter) { translationMatrix.Translate(0, (this.Height - bounds.Height - 5) / 2); } else if (this.TextAlign == ContentAlignment.BottomLeft || this.TextAlign == ContentAlignment.BottomCenter || this.TextAlign == ContentAlignment.BottomRight) { translationMatrix.Translate(0, (this.Height - bounds.Height - 5)); } stroke.Transform(translationMatrix); e.Graphics.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */ e.Graphics.FillPath(Brushes.White, stroke); /* Text */ }
public async Task <CaptchaResult> GetCaptchaResult() { //Color.FromName("SlateBlue"); BackgroundColor = BackgroundColor.IsEmpty ? Color.FromArgb(255, 239, 239, 239) : BackgroundColor; CaptchaFont = CaptchaFont ?? new Font("Tahoma", 12f, FontStyle.Regular); Bitmap image = new Bitmap(ImageWidth, ImageHeight, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(image); graphics.PageUnit = GraphicsUnit.Pixel; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.Clear(BackgroundColor); Random random = new Random(); int number = random.Next((int)Math.Pow(10, NumberOfDigits - 1), (int)Math.Pow(10, NumberOfDigits) - 1); string s = number.NumberToText(Language.Persian); StringFormat format = new StringFormat(); int lcid = new CultureInfo("fa-IR").LCID; format.SetDigitSubstitution(lcid, StringDigitSubstitute.National); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.FormatFlags = StringFormatFlags.DirectionRightToLeft; GraphicsPath path = new GraphicsPath(); path.AddString(s, CaptchaFont.FontFamily, (int)CaptchaFont.Style, (graphics.DpiY * CaptchaFont.SizeInPoints) / 72f, new Rectangle(0, 0, ImageWidth, ImageHeight), format); Graphics graphics2 = Graphics.FromImage(image); HatchStyle[] styleArray = { HatchStyle.BackwardDiagonal }; RectangleF rect = new RectangleF(0f, 0f, ImageWidth, ImageHeight); Brush brush = new HatchBrush(styleArray[random.Next(styleArray.Length - 1)], Color.FromArgb(random.Next(100, 255), random.Next(100, 255), random.Next(100, 255)), Color.White); graphics2.FillRectangle(brush, rect); Pen pen = new Pen(Color.FromArgb(random.Next(0, 100), random.Next(0, 100), random.Next(0, 100))); graphics.DrawPath(pen, path); int num3 = random.Next(-10, 10); using (Bitmap bitmap2 = (Bitmap)image.Clone()) { for (int j = 0; j < ImageHeight; j++) { for (int k = 0; k < ImageWidth; k++) { int x = k + ((int)(num3 * Math.Sin((3.1415926535897931 * j) / 64.0))); int y = j + ((int)(num3 * Math.Cos((3.1415926535897931 * k) / 64.0))); if ((x < 0) || (x >= ImageWidth)) { x = 0; } if ((y < 0) || (y >= ImageHeight)) { y = 0; } image.SetPixel(k, j, bitmap2.GetPixel(x, y)); } } } for (int i = 1; i <= 10; i++) { pen.Color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); int width = random.Next(0, ImageWidth / 3); int num6 = random.Next(0, ImageWidth); int num7 = random.Next(0, ImageHeight); int num8 = num6 - width; int num9 = num7 - width; graphics.DrawEllipse(pen, num8, num9, width, width); } await Task.Run(() => { graphics.DrawImage(image, new Point(0, 0)); }).ConfigureAwait(false); graphics.Flush(); return(new CaptchaResult { Image = image, CreateDate = DateTime.Now, Id = Guid.NewGuid(), Text = number.ToString(CultureInfo.InvariantCulture) }); }
private void textBox1_TextChanged(object sender, EventArgs e) { gp.AddString(textBox1.Text, Font.FontFamily, (int)Font.Style, 20, new System.Drawing.Point(10, 10), StringFormat.GenericDefault); }
public void Render(Graphics g, Size renderSize) { if (Manager.FlightData.HsiOffFlag) { const string toDisplay = "NO HSI DATA"; Brush greenBrush = new SolidBrush(Color.FromArgb(0, 255, 0)); var path = new GraphicsPath(); var sf = new StringFormat(StringFormatFlags.NoWrap) { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; var layoutRectangle = new Rectangle(new Point(0, 0), renderSize); path.AddString(toDisplay, FontFamily.GenericMonospace, (int)FontStyle.Bold, 20, layoutRectangle, sf); g.FillPathFast(greenBrush, path); } else { //draw compass rose if (_compassRose == null) { _compassRose = Resources.hsicompass; } var compassRose = (Bitmap)_compassRose.Clone(); compassRose.MakeTransparent(Color.Black); var currentHeadingInDecimalDegrees = ((Manager.FlightData.MagneticHeadingInDecimalDegrees)) % 360; var whitePen = new Pen(Color.White) { Width = 3 }; Point pointA; Point pointB; Point pointC; Point pointD; Point[] points; Brush whiteBrush = new SolidBrush(Color.White); var airplaneSymbolPointList = new List <Point> { new Point(15, 3), new Point(15, 13), new Point(4, 13), new Point(4, 17), new Point(15, 17), new Point(15, 30), new Point(12, 30), new Point(12, 34), new Point(15, 34), new Point(15, 36), new Point(19, 36), new Point(19, 34), new Point(22, 34), new Point(22, 30), new Point(19, 30), new Point(19, 17), new Point(30, 17), new Point(30, 13), new Point(19, 13), new Point(19, 3) }; //draw airplane symbol var blackPen = new Pen(Color.Black); var airplaneSymbolPoints = airplaneSymbolPointList.ToArray(); g.TranslateTransform((renderSize.Width / 2) - 24, (renderSize.Height / 2) - 9); g.DrawPolygon(blackPen, airplaneSymbolPoints); g.FillPolygon(whiteBrush, airplaneSymbolPoints); g.TranslateTransform(-((renderSize.Width / 2) - 24), -((renderSize.Height / 2) - 9)); //36x40 var toFlag = false; var fromFlag = false; using (var crg = Graphics.FromImage(compassRose)) { crg.SmoothingMode = SmoothingMode.AntiAlias; //compute course deviation and TO/FROM var deviationLimitDecimalDegrees = Manager.FlightData.HsiCourseDeviationLimitInDecimalDegrees % 180; var courseDeviationDecimalDegrees = Manager.FlightData.HsiCourseDeviationInDecimalDegrees; if (Math.Abs(courseDeviationDecimalDegrees) <= 90) { toFlag = true; } else { fromFlag = true; } if (courseDeviationDecimalDegrees < -90) { courseDeviationDecimalDegrees = Common.Math.Util.AngleDelta(Math.Abs(courseDeviationDecimalDegrees), 180) % 180; } else if (courseDeviationDecimalDegrees > 90) { courseDeviationDecimalDegrees = -Common.Math.Util.AngleDelta(courseDeviationDecimalDegrees, 180) % 180; } else { courseDeviationDecimalDegrees = -courseDeviationDecimalDegrees; } if (Math.Abs(courseDeviationDecimalDegrees) > deviationLimitDecimalDegrees) { courseDeviationDecimalDegrees = Math.Sign(courseDeviationDecimalDegrees) * deviationLimitDecimalDegrees; } //draw course deviation ring crg.TranslateTransform((float)compassRose.Width / 2, (float)(compassRose.Height / 2.0) - 1); crg.RotateTransform((Manager.FlightData.HsiDesiredCourseInDegrees) % 360); crg.TranslateTransform(-((float)compassRose.Width / 2), -((float)(compassRose.Height / 2.0) - 1)); if (_courseDeviationDiamond == null) { _courseDeviationDiamond = Resources.hsicoursedeviationdiamond; _courseDeviationDiamond.MakeTransparent(Color.Black); } var courseDeviationDiamond = (Bitmap)_courseDeviationDiamond.Clone(); //draw course deviation diamonds crg.DrawImageFast(courseDeviationDiamond, new Point(101, 166)); crg.DrawImageFast(courseDeviationDiamond, new Point(134, 166)); crg.DrawImageFast(courseDeviationDiamond, new Point(200, 166)); crg.DrawImageFast(courseDeviationDiamond, new Point(233, 166)); //draw HSI TO/FROM flags var toFromFlagSolidColorBrush = Brushes.White; whitePen.Width = 1; //draw TO flag pointA = new Point((compassRose.Width / 2) + 35, (compassRose.Height / 2) - 40); //top pointB = new Point((compassRose.Width / 2) + 45, (compassRose.Height / 2) - 20); //right pointC = new Point((compassRose.Width / 2) + 25, (compassRose.Height / 2) - 20); //left points = new[] { pointA, pointB, pointC }; if (toFlag && Manager.FlightData.HsiDisplayToFromFlag) { crg.FillPolygon(toFromFlagSolidColorBrush, points); } //draw FROM flag pointA = new Point((compassRose.Width / 2) + 25, (compassRose.Height / 2) + 20); //left pointB = new Point((compassRose.Width / 2) + 45, (compassRose.Height / 2) + 20); //right pointC = new Point((compassRose.Width / 2) + 35, (compassRose.Height / 2) + 40); //bottom points = new[] { pointA, pointB, pointC }; if (fromFlag && Manager.FlightData.HsiDisplayToFromFlag) { crg.FillPolygon(toFromFlagSolidColorBrush, points); } //draw HSI Course Deviation Invalid flag var courseInvalidFlagBrush = Brushes.Red; if (Manager.NightMode) { courseInvalidFlagBrush = Brushes.White; } pointA = new Point((compassRose.Width / 2) - 50, (compassRose.Height / 2) - 30); //left top pointB = new Point((compassRose.Width / 2) - 20, (compassRose.Height / 2) - 30); //right top pointC = new Point((compassRose.Width / 2) - 20, (compassRose.Height / 2) - 20); //right bottom pointD = new Point((compassRose.Width / 2) - 50, (compassRose.Height / 2) - 20); //left bottom points = new[] { pointA, pointB, pointC, pointD }; if (Manager.FlightData.HsiDeviationInvalidFlag) { crg.FillPolygon(courseInvalidFlagBrush, points); } whitePen.Width = 2; //draw course indicator needle crg.DrawLineFast(whitePen, new Point((compassRose.Width / 2), 44), new Point((compassRose.Width / 2), 126)); //draw reciprocal-of-course indicator needle crg.DrawLineFast(whitePen, new Point((compassRose.Width / 2), 207), new Point((compassRose.Width / 2), 297)); //draw course pointer triangle pointA = new Point((compassRose.Width / 2), 74); pointB = new Point((compassRose.Width / 2) - 16, 94); pointC = new Point((compassRose.Width / 2) + 16, 94); points = new[] { pointA, pointB, pointC }; crg.FillPolygon(whiteBrush, points); //draw course deviation indicator needle Pen cdiNeedlePen; if (Manager.FlightData.HsiDeviationInvalidFlag) { cdiNeedlePen = Manager.NightMode ? new Pen(Color.White) : new Pen(Color.Yellow); cdiNeedlePen.DashStyle = DashStyle.Dash; cdiNeedlePen.DashCap = DashCap.Flat; cdiNeedlePen.DashPattern = new float[] { 1, 1 }; } else { cdiNeedlePen = new Pen(Color.White); } cdiNeedlePen.Width = 4; var needleX = (compassRose.Width / 2); const int distanceBetweenDiamondCenters = 33; if (deviationLimitDecimalDegrees != 0) { needleX += (int) ((courseDeviationDecimalDegrees / deviationLimitDecimalDegrees) * (distanceBetweenDiamondCenters * 2)); } crg.DrawLineFast(cdiNeedlePen, new Point(needleX, 132), new Point(needleX, 200)); //draw heading bug crg.ResetTransform(); crg.TranslateTransform((float)compassRose.Width / 2, (float)(compassRose.Height / 2.0) - 1); crg.RotateTransform(Manager.FlightData.HsiDesiredHeadingInDegrees % 360); crg.TranslateTransform(-(float)compassRose.Width / 2, -(float)(compassRose.Height / 2.0) - 1); crg.TranslateTransform(154, 6); var bugA = new Point(0, 1); var bugB = new Point(0, 15); var bugC = new Point(35, 15); var bugD = new Point(35, 1); var bugE = new Point(28, 1); var bugF = new Point(19, 13); var bugG = new Point(16, 13); var bugH = new Point(6, 1); var bugPoints = new[] { bugA, bugB, bugC, bugD, bugE, bugF, bugG, bugH }; var headingBugColor = Color.FromArgb(0, 255, 0); Brush headingBugBrush = new SolidBrush(headingBugColor); crg.FillPolygon(headingBugBrush, bugPoints); //draw bearing to beacon indicator var aquaPen = new Pen(Color.Aqua) { Width = 2 }; crg.ResetTransform(); crg.TranslateTransform((float)compassRose.Width / 2, (float)compassRose.Height / 2); crg.RotateTransform(Manager.FlightData.HsiBearingToBeaconInDecimalDegrees % 360); crg.TranslateTransform(-(float)compassRose.Width / 2, -(float)compassRose.Height / 2); var triangleTop = new Point((compassRose.Width / 2), 22); var triangleLeft = new Point((compassRose.Width / 2) - 10, triangleTop.Y + 17); var triangleRight = new Point((compassRose.Width / 2) + 10, triangleTop.Y + 17); crg.FillPolygon(new SolidBrush(aquaPen.Color), new[] { triangleTop, triangleLeft, triangleRight }); //draw bearing to beacon tail on pointer head aquaPen.Width = 5; crg.DrawLineFast(aquaPen, new Point((compassRose.Width / 2), 30), new Point((compassRose.Width / 2), 50)); //draw reciprocal-of-bearing tail aquaPen.Width = 5; crg.DrawLineFast(aquaPen, new Point((compassRose.Width / 2), compassRose.Height - 30), new Point((compassRose.Width / 2), compassRose.Height - 15)); crg.ResetTransform(); } compassRose = (Bitmap)Common.Imaging.Util.RotateBitmap(compassRose, currentHeadingInDecimalDegrees); g.DrawImageUnscaled(compassRose, new Point(120, 29)); whitePen.Width = 3; //draw angle ticks g.DrawLineFast(whitePen, new Point(162, 70), new Point(177, 85)); g.DrawLineFast(whitePen, new Point(108, 199), new Point(130, 199)); g.DrawLineFast(whitePen, new Point(405, 86), new Point(421, 71)); g.DrawLineFast(whitePen, new Point(453, 199), new Point(476, 199)); g.DrawLineFast(whitePen, new Point(406, 313), new Point(421, 328)); g.DrawLineFast(whitePen, new Point(291, 360), new Point(291, 382)); g.DrawLineFast(whitePen, new Point(162, 328), new Point(177, 313)); whitePen.Width = 2; //draw course box pointA = new Point(258, 4); pointB = new Point(258, 34); pointC = new Point(278, 34); pointD = new Point(290, 47); var pointD2 = new Point(291, 47); var pointE = new Point(303, 34); var pointF = new Point(325, 34); var pointG = new Point(325, 4); points = new[] { pointA, pointB, pointC, pointD, pointD2, pointE, pointF, pointG }; whitePen.Width = 1; g.DrawPolygon(whitePen, points); //draw heading numeric value in heading box var headingBoxTextRectangle = new Rectangle(new Point(258, 6), new Size(68, 30)); var headingBoxNumToDisplay = (int)(Math.Round(currentHeadingInDecimalDegrees, 0) % 360); if (Settings.Default.DisplayNorthAsThreeSixZero) { if (headingBoxNumToDisplay == 0) { headingBoxNumToDisplay = 360; } } else { if (headingBoxNumToDisplay == 360) { headingBoxNumToDisplay = 0; } } var headingBoxText = string.Format("{0:000}", headingBoxNumToDisplay); g.DrawStringFast(headingBoxText, _headingBoxFont, whiteBrush, headingBoxTextRectangle); //draw text labels var selectedCourseTextRectangle = new Rectangle(new Point(449, 1), new Size(145, 18)); var selectedHeadingTextRectangle = new Rectangle(new Point(421, 25), new Size(173, 20)); var dmeTextRectangle = new Rectangle(new Point(1, 1), new Size(125, 18)); var textFormat = new StringFormat { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far }; var selectedCourse = (Manager.FlightData.HsiDesiredCourseInDegrees); if (Settings.Default.DisplayNorthAsThreeSixZero) { if (selectedCourse == 0) { selectedCourse = 360; } } else { if (selectedCourse == 360) { selectedCourse = 0; } } var selectedCourseText = string.Format("{0:000}", selectedCourse); g.DrawStringFast("SEL CRS " + selectedCourseText, _textFont, whiteBrush, selectedCourseTextRectangle, textFormat); var selectedHeading = (Manager.FlightData.HsiDesiredHeadingInDegrees); if (Settings.Default.DisplayNorthAsThreeSixZero) { if (selectedHeading == 0) { selectedHeading = 360; } } else { if (selectedHeading == 360) { selectedHeading = 0; } } var selectedHeadingText = string.Format("{0:000}", selectedHeading); g.DrawStringFast("SEL HDG " + selectedHeadingText, _textFont, whiteBrush, selectedHeadingTextRectangle, textFormat); if (Manager.FlightData.HsiDisplayToFromFlag) { var toFromFrequencyPen = Manager.FlightData.HsiDeviationInvalidFlag ? new Pen(Color.Yellow) : new Pen(Color.White); toFromFrequencyPen.Width = 3; /* * //draw TACAN frequency * Brush toFromFrequencyBrush = null; * toFromFrequencyBrush = new SolidBrush(toFromFrequencyPen.Color); * string tacanChannel = this.FlightData.TacanChannel; * StringFormat tacanChannelFormat = new StringFormat(); * tacanChannelFormat.Alignment = StringAlignment.Center; * tacanChannelFormat.LineAlignment = StringAlignment.Center; * Rectangle tacanFrequencyRectangle = new Rectangle(toLineBottomPoint.X - 60, toLineBottomPoint.Y + 3, 120, 20); * g.DrawStringFast(tacanChannel, textFont, toFromFrequencyBrush, tacanFrequencyRectangle, tacanChannelFormat); */ /* * //draw TO/FROM arrow near TACAN frequency * * if (toFlag) * { * g.DrawLineFast(toFromArrowPen, toLineTopPoint, toLineBottomPoint); * g.DrawLineFast(toFromArrowPen, toLineTopPoint.X, toLineTopPoint.Y, toFromArrowLeftX, toLineTopPoint.Y + 10); * g.DrawLineFast(toFromArrowPen, toLineTopPoint.X, toLineTopPoint.Y,toFromArrowRightX, toLineTopPoint.Y + 10); * } * else if (fromFlag) * { * g.DrawLineFast(toFromArrowPen, fromLineTopPoint, fromLineBottomPoint); * g.DrawLineFast(toFromArrowPen, fromLineBottomPoint.X , fromLineBottomPoint.Y, toFromArrowLeftX, fromLineBottomPoint.Y - 10); * g.DrawLineFast(toFromArrowPen, fromLineBottomPoint.X, fromLineBottomPoint.Y, toFromArrowRightX, fromLineBottomPoint.Y - 10); * } */ } var dme = (Manager.FlightData.HsiDistanceToBeaconInNauticalMiles); var dmeText = string.Format("{0:000.0}", dme); textFormat.LineAlignment = StringAlignment.Near; textFormat.Alignment = StringAlignment.Near; g.DrawStringFast(dmeText + " MILES", _textFont, whiteBrush, dmeTextRectangle, textFormat); //draw HSI DME invalid flag if required if (Manager.FlightData.HsiDistanceInvalidFlag) { var currentClip = g.Clip; var clipRectangle = new Rectangle(dmeTextRectangle.X, dmeTextRectangle.Y + 4, dmeTextRectangle.Width, 7); g.Clip = new Region(clipRectangle); const int strokeWidth = 5; var alternate = false; for (var i = dmeTextRectangle.Left - 20; i <= dmeTextRectangle.Right; i += strokeWidth) { var thisColor = Color.Red; if (alternate) { thisColor = Color.White; } var thisPen = new Pen(thisColor) { Width = strokeWidth }; g.DrawLineFast(thisPen, new Point(i, dmeTextRectangle.Bottom), new Point(i + (strokeWidth * 2), dmeTextRectangle.Top)); alternate = !alternate; } g.Clip = currentClip; } if (Manager.FlightData.NavMode != _currentNavMode) { _currentNavModeDisplayedSince = DateTime.UtcNow; _currentNavMode = Manager.FlightData.NavMode; } //draw HSI nav mode if (DateTime.UtcNow.Subtract(_currentNavModeDisplayedSince).TotalSeconds < 2) { var navModeRectangle = new Rectangle(243, 165, 95, 22); var navModeText = string.Format("{0}", _currentNavMode.ToString().ToUpper().Replace("ILS", "ILS/")); textFormat.LineAlignment = StringAlignment.Center; textFormat.Alignment = StringAlignment.Center; var path = new GraphicsPath(); path.AddString(navModeText, FontFamily.GenericSansSerif, (int)FontStyle.Bold, 20, navModeRectangle, textFormat); g.FillPathFast(Brushes.Aqua, path); } } }
public static void DrawIcon(int w, int h, Graphics G, string Label, float huerange = -1) { Bitmap Output = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(Output); TINRSArtWorkRenderer Rend = new TINRSArtWorkRenderer(); Settings TheSettings = Rend.GetHashSettings(Label, huerange); TheSettings.InvertSource = true; //TheSettings.MaxSubDiv = 4; Bitmap TileGfx = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics G3 = Graphics.FromImage(TileGfx); G3.Clear(Color.Transparent); float D = 2; float x1 = D / 2; float x2 = w - x1; float y1 = D / 2; float y2 = h - x1; Font F = new Font("Panton ExtraBold", h * 0.5f, FontStyle.Bold); F = GetAdjustedFont(g, Label, F, w * 0.9f, h * 0.9f, 3, false); var S = g.MeasureString(Label, F); var S2 = g.MeasureString("WO", F); S.Height = S2.Height; float BaseScale = w / 128.0f; GraphicsPath GP = new GraphicsPath(); GP.AddString(Label, new FontFamily("Panton ExtraBold"), 0, F.Size * 1.333333f, new PointF(w / 2 - S.Width / 2, h / 2 - S.Height / 2), new StringFormat()); Bitmap M = new Bitmap(w, h); Graphics G2 = Graphics.FromImage(M); G2.Clear(Color.White); G2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; G2.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; G2.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; G2.SmoothingMode = SmoothingMode.AntiAlias; RenderIconBackdrop(G2, Color.Black, TheSettings, x1, x2, y1, y2, 2, Rend); G2.DrawPath(new Pen(Color.Black, 5), GP); // G2.DrawString(Letter.Text, F, new SolidBrush(Color.White), w / 2 - S.Width / 2, h / 2 - S.Height / 2); G2.DrawPath(new Pen(Color.White, Math.Max(2.0f, 6 * BaseScale)), GP); G2.FillPath(new SolidBrush(Color.White), GP); g.DrawPath(new Pen(TheSettings.BackGroundColor, 5), GP); Rend.BuildTree(M, TheSettings); Rend.BuildStuff(M, TheSettings); g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; float BaseScale2 = 1.0f; // g.FillPath(new SolidBrush(Color.Teal), GP); TheSettings = Rend.GetHashSettings(Label, huerange); RenderIconBackdrop(g, TheSettings.BackGroundColor, TheSettings, x1, x2, y1, y2, 0, Rend); Rend.DrawTiling(TheSettings, M, G3, Color.FromArgb(40, Color.Black), Color.Black, Math.Max(3, 4.5f * BaseScale2), false); Rend.DrawTiling(TheSettings, M, G3, TheSettings.BackgroundHighlight, Color.Black, Math.Max(1.4f, 3 * BaseScale2), false); Rend.DrawTiling(TheSettings, M, G3, Color.FromArgb(100, 255, 255, 0), Color.Black, Math.Max(1.0f, 1.4f * BaseScale2), false); for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { var C = Output.GetPixel(j, i); if (C.A > 0) { var TP = TileGfx.GetPixel(j, i); var C2 = GerberLibrary.MathHelpers.Interpolate(C, TileGfx.GetPixel(j, i), TP.A / 255.0f); Output.SetPixel(j, i, Color.FromArgb(C.A, C2)); } } } g.DrawPath(new Pen(Color.FromArgb(60, Color.Black), 3), GP); g.FillPath(new SolidBrush(Color.FromArgb(255, 255, 255)), GP); G.DrawImage(Output, 0, 0); }
public void UpdatePaint() { // Get device contexts IntPtr screenDc = GetDC(IntPtr.Zero); IntPtr memDc = CreateCompatibleDC(screenDc); IntPtr hBitmap = IntPtr.Zero; IntPtr hOldBitmap = IntPtr.Zero; try { // Get handle to the new bitmap and select it into the current // device context. Bitmap bitmap = new Bitmap(this.Width, this.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics gF = Graphics.FromImage(bitmap)) { SolidBrush brush = new SolidBrush(Color.FromArgb(0, 240, 248, 255)); gF.FillRectangle(brush, 0, 0, bitmap.Width, bitmap.Height); } Font textFont = FormManager.Instace.MyMainForm.MySettingManager.TextFont; // Set parameters for layered window update. FrameSize newSize = new FrameSize(bitmap.Width, bitmap.Height); FramePoint sourceLocation = new FramePoint(0, 0); FramePoint newLocation = new FramePoint(this.Left, this.Top); BLENDFUNCTION blend = new BLENDFUNCTION(); blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = AC_SRC_ALPHA; Graphics g = Graphics.FromImage(bitmap); Color OutlineForeColor = FormManager.Instace.MyMainForm.MySettingManager.OutLineColor1; float OutlineWidth = 2; using (GraphicsPath gp = new GraphicsPath()) using (Pen outline = new Pen(OutlineForeColor, OutlineWidth) { LineJoin = LineJoin.Round }) using (StringFormat sf = new StringFormat()) using (Brush foreBrush = new SolidBrush(FormManager.Instace.MyMainForm.MySettingManager.TextColor)) { sf.Alignment = stringFormat.Alignment; Color backgroundColor = Color.FromArgb(alpha, Color.AliceBlue); g.Clear(backgroundColor); Rectangle rectangle = ClientRectangle; rectangle.X = 15; rectangle.Y = 15; rectangle.Width -= 15; rectangle.Height -= 15; if (isActiveGDI) { try { gp.AddString(resultText, textFont.FontFamily, (int)textFont.Style, g.DpiY * textFont.Size / 72, rectangle, sf); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); TransFormLayer.isActiveGDI = false; CustomLabel.isActiveGDI = false; if (DialogResult.OK == MessageBox.Show("GDI+ 가 작동하지 않습니다. \n레이어 번역창의 일부 기능을 사용할 수 없습니다.\n해결법을 확인해 보겠습니까? ", "GDI+ 에서 일반 오류가 발생했습니다.", MessageBoxButtons.OKCancel)) { try { System.Diagnostics.Process.Start("https://blog.naver.com/killkimno/70185869419"); } catch { } } } } g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; if (isStart) { if (FormManager.Instace.MyMainForm.MySettingManager.NowIsUseBackColor) { CharacterRange[] characterRanges = { new CharacterRange(0, resultText.Length) }; sf.SetMeasurableCharacterRanges(characterRanges); Region[] stringRegions = g.MeasureCharacterRanges(resultText, textFont, rectangle, sf); if (stringRegions.Length > 0) { // Draw rectangle for first measured range. RectangleF measureRect1 = stringRegions[0].GetBounds(g); SolidBrush backColorBrush = new SolidBrush(FormManager.Instace.MyMainForm.MySettingManager.BackgroundColor); g.FillRectangle(backColorBrush, measureRect1.X - 8, measureRect1.Y - 4, measureRect1.Width + 16, measureRect1.Height + 8); } } } else { using (Pen layerOutline = new Pen(Color.FromArgb(40, 134, 249), 3) { LineJoin = LineJoin.Round }) g.DrawRectangle(layerOutline, ClientRectangle); } g.SmoothingMode = SmoothingMode.HighQuality; if (isActiveGDI) { using (Pen outline2 = new Pen(FormManager.Instace.MyMainForm.MySettingManager.OutLineColor2, 5) { LineJoin = LineJoin.Round }) g.DrawPath(outline2, gp); g.DrawPath(outline, gp); g.FillPath(foreBrush, gp); } else { g.DrawString(resultText, textFont, foreBrush, rectangle); } } hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); //Set the fact that background is transparent hOldBitmap = SelectObject(memDc, hBitmap); // Update the window. UpdateLayeredWindow( this.Handle, // Handle to the layered window screenDc, // Handle to the screen DC ref newLocation, // New screen position of the layered window ref newSize, // New size of the layered window memDc, // Handle to the layered window surface DC ref sourceLocation, // Location of the layer in the DC 0, // Color key of the layered window ref blend, // Transparency of the layered window ULW_ALPHA // Use blend as the blend function ); //SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); } finally { // Release device context. ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { SelectObject(memDc, hOldBitmap); DeleteObject(hBitmap); } DeleteDC(memDc); GC.Collect(); /* * IntPtr screenDc = GetDC(IntPtr.Zero); * IntPtr memDc = CreateCompatibleDC(screenDc); * IntPtr hBitmap = IntPtr.Zero; * IntPtr hOldBitmap = IntPtr.Zero; */ } Util.ShowLog("end"); }
private void GenerateImage() { // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, Width, Height); // Fill in the background. HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = height; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(FontFamily, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; }
private void generateImage() { if (!isDirty) { return; } // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. using (Graphics g = Graphics.FromImage(bitmap)) { g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, width, height); // Fill in the background. HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, backgroundDark, backgroundLight); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = rect.Height + 1; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(familyName, fontSize, fontStyle); 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); Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); if (System.Environment.OSVersion.Platform != PlatformID.Unix) { 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) }; path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); } else { float xtr = (rect.Size.Width - size.Width) / 2F + size.Width / 10F; float ytr = (rect.Size.Height - size.Height) / 2F; matrix.Rotate((float)random.NextDouble() * 10F - 5F); matrix.Shear((float)random.NextDouble() * 1F - 0.5F, 0F); matrix.Translate(xtr, ytr); path.Transform(matrix); } // Draw the text. using (hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, foregroundLight, foregroundDark)) { g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = random.Next(rect.Width); int y = random.Next(rect.Height); int w = random.Next(m / 50); int h = random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } } // Clean up. font.Dispose(); } // Set the image. image = bitmap; isDirty = false; }
/**/ public void AddData(byte[] Data) { for (int i = 0; i < Data.Length; i++) { Datalist.Add(Data[i]); //链表尾部添加数据 } Invalidate(); //刷新显示 } public void ResData() { try { byte[] data = new byte[Form1.serialPort1.BytesToRead]; if (Form1.serialPort1.IsOpen) { Form1.serialPort1.Read(data, 0, data.Length); } AddData(data); } catch { } } /**/ private void Draw_Paint(object sender, PaintEventArgs e) { ResData(); int x, y; string str; Graphics g = e.Graphics; Rectangle rect = new Rectangle(0, Startprint, ClientRectangle.Width, ClientRectangle.Height / 2); GraphicsPath path = new GraphicsPath(new Point[] { new Point(0, 16), //new Point(50,50), //new Point(10,80), //new Point(50,100), new Point(0, 448) }, new byte[] { (byte)PathPointType.Start, //(byte)PathPointType.Line, //(byte)PathPointType.Line, //(byte)PathPointType.Line, (byte)PathPointType.CloseSubpath }); GraphicsPath gp_x = new GraphicsPath(); GraphicsPath gp_y = new GraphicsPath(); ResData(); try { int num_x = this.ClientRectangle.Width / Unit_lenth; //27 int num_y = this.ClientRectangle.Height / Unit_lenth; //17 int list_count = (this.ClientRectangle.Width - Startprint); //852 for (y = 0; y < this.ClientRectangle.Width / Unit_lenth; y++) //纵轴线 { g.DrawLine(AxislinesPen, Startprint + y * Unit_lenth, Startprint, Startprint + y * Unit_lenth, Y_MAX + Startprint); //添加横轴时间 if ((y * Drawstep) / 10 == 0) { gp_x.AddString((y * Drawstep).ToString(), this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(Startprint + y * Unit_lenth - 7, this.ClientRectangle.Height - Startprint + 10, 400, 50), null); } else if (((y * Drawstep) / 10 != 0) && ((y * Drawstep) / 100 == 0)) { gp_x.AddString((y * Drawstep).ToString(), this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(Startprint + y * Unit_lenth - 9, this.ClientRectangle.Height - Startprint + 10, 400, 50), null); } else if (((y * Drawstep) / 100 != 0)) { gp_x.AddString((y * Drawstep).ToString(), this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(Startprint + y * Unit_lenth - 11, this.ClientRectangle.Height - Startprint + 10, 400, 50), null); } } for (x = 0; x < this.ClientRectangle.Height / Unit_lenth; x++) //横轴线 { g.DrawLine(AxislinesPen, Startprint, (x + 1) * Unit_lenth, this.ClientRectangle.Width, (x + 1) * Unit_lenth); str = ((16 - x) * 16).ToString("X"); str = "0x" + (str.Length == 1 ? str + "0" : str); if (x == 0) { str = "0xFF"; } if (x == 17) { break; } gp_y.AddString(str, this.Font.FontFamily, (int)FontStyle.Regular, 12, new RectangleF(0, Startprint + x * Unit_lenth - 8, 400, 50), null); } e.Graphics.DrawPath(Pens.White, gp_x); e.Graphics.DrawPath(Pens.White, gp_y); } catch { } // 如果数据量大于可容纳的数据量,删除最左的数据 (107) if (Datalist.Count - 1 >= (this.ClientRectangle.Width - Startprint) / Drawstep) { Datalist.RemoveRange(0, Datalist.Count - ((this.ClientRectangle.Width - Startprint) / Drawstep - 1)); } for (int i = 0; i < Datalist.Count - 1; i++) { g.DrawLine(WavelinsPen, Startprint + i * Drawstep, 17 * Unit_lenth - Datalist[i] * 2, Startprint + (i + 1) * Drawstep, 17 * Unit_lenth - Datalist[i + 1] * 2); } }
private void GenerateImage() { Bitmap bitmap = new Bitmap (this.width, this.height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.Plaid, Color.White, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(this.text, font.FontFamily, (int)font.Style, 40, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next( rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.Percent90, Color.FromArgb(128, 128, 128), Color.Gray); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 200F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }
//Use the OnPaint overrides sub to paint the control to match how all the properties settings have been set by the user protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { var _with1 = e.Graphics; //Fill the background with the BackColor color _with1.FillRectangle(_BackgroundBrush, new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height)); //If the BackgroundImage property has been set to an image then draw the BackgroundImage if (this.BackgroundImage != null) { DrawBackImage(e.Graphics); } //If the Image property has been set to an image then draw the image on the control if (_Image != null) { _with1.DrawImage(_Image, AlignImage(new Rectangle(0, 0, this.Width - 1, this.Height - 1))); } //If the Text property has bet assigned any text then draw the text on the control if (!string.IsNullOrEmpty(this.Text)) { //Set the smothing mode of the graphics to make things look smother //_with1.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias; _with1.SmoothingMode = SmoothingMode.AntiAlias; //The Drawing2D.GraphicsPath used for drawing and/or filling the text using (GraphicsPath pth = new GraphicsPath()) { //The StringFormat used to align the text in the Label using (StringFormat sf = new StringFormat()) { //Use (ta) which is an integer value of the ContentAlignment integer enum to set the //Alignment of the text that will be added to the Drawing2D.GraphicsPath int ta = Convert.ToInt32(_TextAlign); if (ta < 8) { sf.LineAlignment = StringAlignment.Near; } else if (ta < 128) { sf.LineAlignment = StringAlignment.Center; ta = ta / 16; } else { sf.LineAlignment = StringAlignment.Far; ta = ta / 256; } if (ta == Convert.ToInt32(ContentAlignment.TopLeft)) { sf.Alignment = StringAlignment.Near; } else if (ta == Convert.ToInt32(ContentAlignment.TopCenter)) { sf.Alignment = StringAlignment.Center; } else if (ta == Convert.ToInt32(ContentAlignment.TopRight)) { sf.Alignment = StringAlignment.Far; } //Add the text to the Drawing2D.GraphicsPath using the StringFormat pth.AddString(this.Text, this.Font.FontFamily, Convert.ToInt32(this.Font.Style), Convert.ToSingle((_with1.DpiY * this.Font.Size) / 72), new Rectangle(this.Padding.Left, this.Padding.Top, (this.ClientSize.Width - 1) - (this.Padding.Left + this.Padding.Right), (this.ClientSize.Height - 1) - (this.Padding.Top + this.Padding.Bottom)), sf); } //If the ShowTextShadow property is set to true then draw the shadow if (_ShowTextShadow) { //Use the ShadowPosition property to set the Graphics.TranslateTransform to draw the //shadow at the correct offset position. if (_ShadowPosition == ShadowArea.TopLeft) { _with1.TranslateTransform(-_ShadowDepth, -_ShadowDepth); } else if (_ShadowPosition == ShadowArea.TopRight) { _with1.TranslateTransform(+_ShadowDepth, -_ShadowDepth); } else if (_ShadowPosition == ShadowArea.BottomLeft) { _with1.TranslateTransform(-_ShadowDepth, +_ShadowDepth); } else { _with1.TranslateTransform(+_ShadowDepth, +_ShadowDepth); } if (_ShadowStyle == ShadowDrawingType.DrawShadow) { //Draw the Drawing2D.GraphicsPath with the _ShadowPen that is set to the ShadowColor having the ShadowTransparency _with1.DrawPath(_ShadowPen, pth); //Draws the shadow } else { //Fill the Drawing2D.GraphicsPath with the _ShadowBrush that is set to the ShadowColor having the ShadowTransparency _with1.FillPath(_ShadowBrush, pth); //Draws the shadow } //Now use the Graphics.TranslateTransform to shift the graphics back in the opposite //direction before Drawing and Filling the Drawing2D.GraphicsPath again with text colors if (_ShadowPosition == ShadowArea.TopLeft) { _with1.TranslateTransform(+(_ShadowDepth * 2), +(_ShadowDepth * 2)); } else if (_ShadowPosition == ShadowArea.TopRight) { _with1.TranslateTransform(-(_ShadowDepth * 2), +(_ShadowDepth * 2)); } else if (_ShadowPosition == ShadowArea.BottomLeft) { _with1.TranslateTransform(+(_ShadowDepth * 2), -(_ShadowDepth * 2)); } else { _with1.TranslateTransform(-(_ShadowDepth * 2), -(_ShadowDepth * 2)); } } //If the TextPatternImage property has been set to an image then fill the center of the text with the image //else the center will be filled with a soloid color of the ForeColor property. if (_TextPatternImage != null) { //Use the TextPatternImageLayout property to resize and/or position the TextPatternImage Rectangle br = new Rectangle(); RectangleF r = pth.GetBounds(); if (_TextPatternImageLayout == PatternLayout.Normal | _TextPatternImageLayout == PatternLayout.Tile) { br = new Rectangle(Convert.ToInt32(r.X) + 1, Convert.ToInt32(r.Y + 1), _TextPatternImage.Width + 1, _TextPatternImage.Height + 1); } else if (_TextPatternImageLayout == PatternLayout.Center) { int xx = Convert.ToInt32((r.X + 1) + ((r.Width / 2) - (_TextPatternImage.Width / 2))); int yy = Convert.ToInt32((r.Y + 1) + ((r.Height / 2) - (_TextPatternImage.Height / 2))); br = new Rectangle(xx, yy, _TextPatternImage.Width + 1, _TextPatternImage.Height + 1); } else if (_TextPatternImageLayout == PatternLayout.Stretch) { br = new Rectangle(Convert.ToInt32(r.X) + 1, Convert.ToInt32(r.Y + 1), Convert.ToInt32(r.Width) + 1, Convert.ToInt32(r.Height) + 1); } using (Bitmap patBmp = new Bitmap(_TextPatternImage, br.Width, br.Height)) { //Use a TextureBrush with the TextPatternImage assigned as the texture image using (TextureBrush tb = new TextureBrush(patBmp)) { //If the TextPatternImageLayout property is not set to Tile then set the set the //TextureBrush`s WrapMode to Clamp to stop it from tiling the image. if (!(_TextPatternImageLayout == PatternLayout.Tile)) { tb.WrapMode = WrapMode.Clamp; } tb.TranslateTransform(br.X, br.Y); //Fill the GraphicsPath with the TextureBrush. _with1.FillPath(tb, pth); } } } else { //Fill the GraphicsPath with a soloid color of the ForeColor property. _with1.FillPath(_CenterBrush, pth); } //Draw the GraphicsPath with the OutlineColor. _with1.DrawPath(_OutLinePen, pth); } } //If the BorderStyle property is other than None then call the DrawBorder sub to draw the border if (_BorderStyle != BorderType.None) { DrawLabelBorder(e.Graphics, new Rectangle(0, 0, this.Width - 1, this.Height - 1)); } }
public IEnumerable <MapObject> Create(IDGenerator generator, Box box, ITexture texture, int roundDecimals) { var width = box.Width; var length = Math.Max(1, Math.Abs((int)box.Length)); var height = box.Height; var flatten = (float)_flattenFactor.Value; var text = _text.GetValue(); var family = _fontChooser.GetFontFamily(); var style = Enum.GetValues(typeof(FontStyle)).OfType <FontStyle>().FirstOrDefault(fs => family.IsStyleAvailable(fs)); if (!family.IsStyleAvailable(style)) { family = FontFamily.GenericSansSerif; } var set = new PolygonSet(); var sizes = new List <RectangleF>(); using (var bmp = new Bitmap(1, 1)) { using (var g = System.Drawing.Graphics.FromImage(bmp)) { using (var font = new Font(family, length, style, GraphicsUnit.Pixel)) { for (var i = 0; i < text.Length; i += 32) { using (var sf = new StringFormat(StringFormat.GenericTypographic)) { var rem = Math.Min(text.Length, i + 32) - i; var range = Enumerable.Range(0, rem).Select(x => new CharacterRange(x, 1)).ToArray(); sf.SetMeasurableCharacterRanges(range); var reg = g.MeasureCharacterRanges(text.Substring(i, rem), font, new RectangleF(0, 0, float.MaxValue, float.MaxValue), sf); sizes.AddRange(reg.Select(x => x.GetBounds(g))); } } } } } var xOffset = box.Start.DX; var yOffset = box.End.DY; for (var ci = 0; ci < text.Length; ci++) { var c = text[ci]; var size = sizes[ci]; var gp = new GraphicsPath(); gp.AddString(c.ToString(), family, (int)style, length, new PointF(0, 0), StringFormat.GenericTypographic); gp.Flatten(new System.Drawing.Drawing2D.Matrix(), flatten); var polygons = new List <Polygon>(); var poly = new List <PolygonPoint>(); for (var i = 0; i < gp.PointCount; i++) { var type = gp.PathTypes[i]; var point = gp.PathPoints[i]; poly.Add(new PolygonPoint(point.X + xOffset, -point.Y + yOffset)); if ((type & 0x80) == 0x80) { polygons.Add(new Polygon(poly)); poly.Clear(); } } var tri = new List <Polygon>(); Polygon polygon = null; foreach (var p in polygons) { if (polygon == null) { polygon = p; tri.Add(p); } else if (p.CalculateWindingOrder() != polygon.CalculateWindingOrder()) { polygon.AddHole(p); } else { polygon = null; tri.Add(p); } } foreach (var pp in tri) { try { P2T.Triangulate(pp); set.Add(pp); } catch { // Ignore } } xOffset += size.Width; } var zOffset = box.Start.Z; foreach (var polygon in set.Polygons) { foreach (var t in polygon.Triangles) { var points = t.Points.Select(x => new Coordinate((decimal)x.X, (decimal)x.Y, zOffset).Round(roundDecimals)).ToList(); var faces = new List <Coordinate[]>(); // Add the vertical faces var z = new Coordinate(0, 0, height).Round(roundDecimals); for (var j = 0; j < points.Count; j++) { var next = (j + 1) % points.Count; faces.Add(new[] { points[j], points[j] + z, points[next] + z, points[next] }); } // Add the top and bottom faces faces.Add(points.ToArray()); faces.Add(points.Select(x => x + z).Reverse().ToArray()); // Nothing new here, move along var solid = new Solid(generator.GetNextObjectID()) { Colour = Colour.GetRandomBrushColour() }; foreach (var arr in faces) { var face = new Face(generator.GetNextFaceID()) { Parent = solid, Plane = new Plane(arr[0], arr[1], arr[2]), Colour = solid.Colour, Texture = { Texture = texture } }; face.Vertices.AddRange(arr.Select(x => new Vertex(x, face))); face.UpdateBoundingBox(); face.AlignTextureToFace(); solid.Faces.Add(face); } solid.UpdateBoundingBox(); yield return(solid); } } }
public void DrawString(string text, Font font, Brush brush1, float x, float y) { if (text == null || text == "") { return; } var brush = (SolidBrush)brush1; var fontsize = font.Size; Pen _p = new Pen(brush.Color, 2); float maxy = 1; foreach (char cha in text) { int charno = (int)cha; int charid = charno ^ (int)(fontsize * 1000) ^ brush.Color.ToArgb(); if (!charDict.ContainsKey(charid)) { charDict[charid] = new character() { bitmap = new Bitmap(128, 128, System.Drawing.Imaging.PixelFormat.Format32bppArgb), size = (int)fontsize }; charDict[charid].bitmap.MakeTransparent(Color.Transparent); //charbitmaptexid float maxx = 0;// this.Width / 150; // for space // create bitmap using (var gfx = Graphics.FromImage(charDict[charid].bitmap)) { var pth = new GraphicsPath(); if (text != null) { pth.AddString(cha + "", font.FontFamily, 0, fontsize + 2, new Point((int)0, (int)0), StringFormat.GenericTypographic); } charDict[charid].pth = pth; gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; //gfx.DrawPath(_p, pth); //Draw the face gfx.FillPath(brush, pth); if (pth.PointCount > 0) { foreach (PointF pnt in pth.PathPoints) { if (pnt.X > maxx) { maxx = pnt.X; } if (pnt.Y > maxy) { maxy = pnt.Y; } } } } charDict[charid].width = (int)(maxx + 2); //charbitmaps[charid] = charbitmaps[charid].Clone(new RectangleF(0, 0, maxx + 2, maxy + 2), charbitmaps[charid].PixelFormat); //charbitmaps[charno * (int)fontsize].Save(charno + " " + (int)fontsize + ".png"); // create texture int textureId; GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvModeCombine.Replace); //Important, or wrong color on some computers Bitmap bitmap = charDict[charid].bitmap; GL.GenTextures(1, out textureId); GL.BindTexture(TextureTarget.Texture2D, textureId); BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); GL.Flush(); bitmap.UnlockBits(data); charDict[charid].gltextureid = textureId; } float scale = 1.0f; // dont draw spaces if (cha != ' ') { /* * TranslateTransform(x, y); * DrawPath(this._p, charDict[charid].pth); * * //Draw the face * * FillPath(brush, charDict[charid].pth); * * TranslateTransform(-x, -y); */ GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, charDict[charid].gltextureid); GL.Begin(PrimitiveType.TriangleFan); GL.TexCoord2(0, 0); GL.Vertex2(x, y); GL.TexCoord2(1, 0); GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y); GL.TexCoord2(1, 1); GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y + charDict[charid].bitmap.Height * scale); GL.TexCoord2(0, 1); GL.Vertex2(x + 0, y + charDict[charid].bitmap.Height * scale); GL.End(); //GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Texture2D); } x += charDict[charid].width * scale; } }
private void Render(IGraphics ig) { string s = cbWhat.Text; if (string.IsNullOrEmpty(s)) { } else if (s == "Clipping") { Pen pn = new Pen(Color.LightGray, 5); Pen pn2 = new Pen(Color.Yellow); ig.Clear(Color.Black); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.SetClip(new Rectangle(35, 35, 120, 120)); ig.DrawRectangle(pn, 5, 5, 45, 70); ig.DrawRectangle(pn, 15, 25, 90, 120); ig.DrawRectangle(pn, 50, 30, 100, 170); ig.DrawRectangle(pn, 5, 80, 180, 30); ig.DrawRectangle(pn, 75, 10, 40, 160); ig.EndContainer(cnt); ig.DrawRectangle(pn2, 5, 5, 45, 70); ig.DrawRectangle(pn2, 15, 25, 90, 120); ig.DrawRectangle(pn2, 50, 30, 100, 170); ig.DrawRectangle(pn2, 5, 80, 180, 30); ig.DrawRectangle(pn2, 75, 10, 40, 160); } else if (s == "Transforms") { ig.Clear(Color.Black); ig.RotateTransform(15); ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.Red, 2), 260, 80, 50, 40); ig.TranslateTransform(15, -5); GraphicsContainer cnt = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; ig.RotateTransform(5); ig.FillEllipse(new SolidBrush(Color.Orange), 100, 100, 80, 40); ig.DrawRectangle(new Pen(Color.Orange, 2), 60, 80, 40, 40); GraphicsContainer cnt2 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.None; ig.RotateTransform(5); ig.ScaleTransform(1.1f, 1.2f); ig.FillEllipse(new SolidBrush(Color.YellowGreen), 130, 180, 80, 40); ig.DrawRectangle(new Pen(Color.YellowGreen, 2), 62, 80, 40, 40); GraphicsContainer cnt3 = ig.BeginContainer(); ig.SmoothingMode = SmoothingMode.HighQuality; Matrix mm = new Matrix(); mm.Shear(0.3f, 0f); ig.Transform = mm; ig.FillEllipse(new SolidBrush(Color.Green), 180, 120, 80, 40); ig.DrawRectangle(new Pen(Color.Green, 2), 62, 84, 40, 40); ig.EndContainer(cnt3); ig.EndContainer(cnt2); ig.FillEllipse(new SolidBrush(Color.Blue), 120, 150, 80, 40); ig.DrawRectangle(new Pen(Color.Blue, 2), 64, 80, 40, 40); ig.EndContainer(cnt); ig.FillEllipse(new SolidBrush(Color.Indigo), 80, 210, 80, 40); ig.DrawRectangle(new Pen(Color.Indigo, 2), 66, 80, 40, 40); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); ig.ResetTransform(); ig.DrawRectangle(new Pen(Color.White, 2), 270, 30, 50, 40); } else if (s == "Lines") { ig.SmoothingMode = SmoothingMode.AntiAlias; Pen ow = new Pen(Color.Purple, 12); ow.EndCap = LineCap.Round; ow.StartCap = LineCap.Round; ow.MiterLimit = 6f; ow.LineJoin = LineJoin.Miter; ig.SmoothingMode = SmoothingMode.None; Pen tp = new Pen(Color.Red, 2); tp.DashStyle = DashStyle.DashDot; ig.DrawLine(tp, 70, 20, 190, 20); tp.DashStyle = DashStyle.Dash; ig.DrawLine(tp, 70, 30, 190, 30); tp.DashStyle = DashStyle.Custom; tp.DashPattern = new float[] { 1, 8, 2, 2 }; ig.DrawLine(tp, 70, 40, 190, 40); ig.SmoothingMode = SmoothingMode.AntiAlias; PointF[] pts = new PointF[4]; pts[0] = new PointF(20, 50); pts[1] = new PointF(30, 90); pts[2] = new PointF(65, 60); pts[3] = new PointF(50, 40); ig.DrawLines(ow, pts); Point[] polly = new Point[] { new Point(200, 40), new Point(220, 140), new Point(240, 100), new Point(290, 70), new Point(230, 10) }; ig.DrawPolygon(tp, polly); //arrows Pen arr = new Pen(Color.DarkGoldenrod, 5); { arr.Width = 2; arr.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; const float arrowWidth = 11.0f; // TUNE: const float arrowHeight = 14f; // TUNE: var arrowOutline = new System.Drawing.Drawing2D.GraphicsPath(); arrowOutline.AddLines(new PointF[] { new PointF(-(arrowWidth / 2), -arrowHeight), new PointF(0, 0), new PointF((arrowWidth / 2), -arrowHeight), new PointF(-(arrowWidth / 2), -arrowHeight) }); var generalizationArrow = new System.Drawing.Drawing2D.CustomLineCap(null, arrowOutline); generalizationArrow.SetStrokeCaps(System.Drawing.Drawing2D.LineCap.Round, System.Drawing.Drawing2D.LineCap.Round); generalizationArrow.BaseInset = arrowHeight; arr.CustomEndCap = generalizationArrow; ig.DrawLine(arr, 0, 120, 100, 200); } arr.Width = 5; AdjustableArrowCap aac = new AdjustableArrowCap(5, 3, false); arr.EndCap = LineCap.Custom; arr.CustomEndCap = aac; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 50, 120, 150, 200); arr.Width = 7f; arr.EndCap = LineCap.RoundAnchor; arr.StartCap = LineCap.SquareAnchor; ig.DrawLine(arr, 100, 120, 200, 200); arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.ArrowAnchor; ig.DrawLine(arr, 150, 120, 250, 200); Point[] al = new Point[] { new Point(200, 100), new Point(300, 200), new Point(300, 150) }; arr.Width = 9; arr.EndCap = LineCap.DiamondAnchor; arr.StartCap = LineCap.DiamondAnchor; ig.DrawLines(arr, al); } else if (s == "Curves") { PointF[] bezzie = new PointF[] { new PointF(20, 150), new PointF(110, 190), new PointF(120, 200), new PointF(50, 220), new PointF(60, 200), new PointF(140, 180), new PointF(100, 160), new PointF(180, 260), new PointF(200, 210), new PointF(190, 210) }; Pen bpn = new Pen(Color.MediumSeaGreen, 2); bpn.DashStyle = DashStyle.Custom; bpn.DashPattern = new float[] { 6, 1, 5, 2, 4, 3, 3, 4, 2, 5, 6, 1 }; ig.DrawBeziers(bpn, bezzie); PointF[] curvy = new PointF[] { new PointF(130, 40), new PointF(70, 70), new PointF(50, 20), new PointF(120, 120), new PointF(150, 80), new PointF(80, 150), new PointF(80, 110) }; ig.DrawCurve(new Pen(Color.Blue, 5), curvy); ig.DrawCurve(new Pen(Color.Red, 2), curvy, 2, 3); ig.DrawCurve(new Pen(Color.Yellow, 1), curvy, 1f); Point[] ccurvy = new Point[] { new Point(280, 30), new Point(260, 60), new Point(200, 20), new Point(290, 120), new Point(290, 80), new Point(230, 150), new Point(150, 50) }; ig.DrawClosedCurve(new Pen(Color.Green, 3), ccurvy, 1f, FillMode.Alternate); ig.DrawClosedCurve(new Pen(Color.Purple, 1), ccurvy, 0f, FillMode.Alternate); Point[] fcc = new Point[] { new Point(160, 350), new Point(190, 370), new Point(130, 390), new Point(190, 400), new Point(195, 410), new Point(100, 430), new Point(160, 450) }; ig.FillClosedCurve(new SolidBrush(Color.Red), fcc, FillMode.Winding, 1f); ig.FillClosedCurve(new SolidBrush(Color.Aquamarine), fcc, FillMode.Alternate, .2f); } else if (s == "Transparency") { Point[] fillpoly = new Point[] { new Point(20, 130), new Point(60, 90), new Point(30, 20), new Point(80, 20), new Point(15, 90), new Point(100, 50), new Point(0, 50) }; Color col = Color.FromArgb(96, 255, 0, 0); ig.FillEllipse(new SolidBrush(Color.Ivory), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(Color.Ivory), fillpoly, FillMode.Winding); ig.TranslateTransform(10, 10); ig.FillEllipse(new SolidBrush(col), 60, 140, 60, 30); ig.FillPolygon(new SolidBrush(col), fillpoly, FillMode.Alternate); ig.ResetTransform(); ig.FillPie(new SolidBrush(Color.FromArgb(100, 255, 0, 0)), 10, 200, 200, 80, 315, 90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 128, 0)), 10, 200, 200, 80, 250, -90); ig.FillPie(new SolidBrush(Color.FromArgb(100, 128, 0, 128)), 15, 205, 190, 70, 180, 270); ig.FillPie(new SolidBrush(Color.FromArgb(100, 200, 60, 60)), 20, 210, 180, 60, 45, -270); } else if (s == "Fills") { LinearGradientBrush gbr1 = new LinearGradientBrush(new Point(0, 0), new Point(30, 20), Color.Blue, Color.Plum); ColorBlend blend = new ColorBlend(3); blend.Colors = new Color[] { Color.Red, Color.Yellow, Color.MediumSlateBlue }; blend.Positions = new float[] { 0, .3f, 1f }; gbr1.InterpolationColors = blend; Point[] sp = new Point[] { new Point(145, 145), new Point(305, 250), new Point(220, 250), new Point(180, 250) }; ig.FillPolygon(gbr1, sp); LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue); gbr2.WrapMode = WrapMode.TileFlipXY; Point[] sp2 = new Point[] { new Point(25, 205), new Point(75, 150), new Point(110, 110), new Point(40, 80) }; ig.FillPolygon(gbr2, sp2); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalBrick, Color.Khaki, Color.Peru), 000, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Vertical, Color.Bisque, Color.Peru), 020, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DarkVertical, Color.Tan, Color.Peru), 040, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Peru), 060, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.BurlyWood, Color.Peru), 080, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LargeConfetti, Color.Wheat, Color.Peru), 100, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.ZigZag, Color.SaddleBrown, Color.Peru), 120, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.HorizontalBrick, Color.Linen, Color.Peru), 140, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.LightHorizontal, Color.Maroon, Color.Peru), 160, 5, 20, 20); ig.FillRectangle(gbr1, 200, 5, 20, 20); ig.FillRectangle(gbr2, 220, 5, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent05, Color.CornflowerBlue, Color.LemonChiffon), 000, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent10, Color.CornflowerBlue, Color.LemonChiffon), 020, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent20, Color.CornflowerBlue, Color.LemonChiffon), 040, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent25, Color.CornflowerBlue, Color.LemonChiffon), 060, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent30, Color.CornflowerBlue, Color.LemonChiffon), 080, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent40, Color.CornflowerBlue, Color.LemonChiffon), 100, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent50, Color.CornflowerBlue, Color.LemonChiffon), 120, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent60, Color.CornflowerBlue, Color.LemonChiffon), 140, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent70, Color.CornflowerBlue, Color.LemonChiffon), 160, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent75, Color.CornflowerBlue, Color.LemonChiffon), 180, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent80, Color.CornflowerBlue, Color.LemonChiffon), 200, 30, 20, 20); ig.FillRectangle(new HatchBrush(HatchStyle.Percent90, Color.CornflowerBlue, Color.LemonChiffon), 220, 30, 20, 20); } else if (s == "Arcs/Pies") { //GDI does not seem to draw arcs correctly except when the ellipse is a circle. //These arcs demonstrate the problem. SVGGraphics calculates arcs correctly. ig.DrawArc(new Pen(Color.Black, 2), 120 + 5 * 3, 120, 110 * 3, 110, 0, 240); ig.DrawArc(new Pen(Color.Black, 2), 120 + 10 * 3, 125, 100 * 3, 100, 0, 210); ig.DrawArc(new Pen(Color.Black, 2), 120 + 15 * 3, 130, 90 * 3, 90, 0, 180); ig.DrawArc(new Pen(Color.Black, 2), 120 + 20 * 3, 135, 80 * 3, 80, 0, 150); ig.DrawArc(new Pen(Color.Black, 2), 120 + 25 * 3, 140, 70 * 3, 70, 0, 120); ig.DrawArc(new Pen(Color.Black, 2), 120 + 30 * 3, 145, 60 * 3, 60, 0, 90); ig.DrawArc(new Pen(Color.Black, 2), 120 + 35 * 3, 150, 50 * 3, 50, 0, 60); ig.DrawArc(new Pen(Color.Black, 2), 120 + 40 * 3, 155, 40 * 3, 40, 0, 270); ig.DrawPie(new Pen(Color.Pink, 2), 110, 50, 100, 100, 315, 90); ig.DrawPie(new Pen(Color.Purple, 2), 110, 50, 100, 100, 250, -90); ig.DrawPie(new Pen(Color.DarkRed, 2), 115, 55, 90, 90, 180, 270); ig.DrawPie(new Pen(Color.Red, 2), 120, 60, 80, 80, 45, -270); } else if (s == "Text") { Font fnt1 = new Font("Helvetica", 12, FontStyle.Italic | FontStyle.Bold); Font fnt2 = new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold); Font fnt3 = new Font("", 40, FontStyle.Underline); Rectangle rc1 = new Rectangle(30, 30, 220, 20); StringFormat fmt1 = new StringFormat(); fmt1.Alignment = StringAlignment.Near; ig.DrawRectangle(new Pen(Color.Blue), rc1); ig.DrawString("Text...1", fnt1, new SolidBrush(Color.DarkGreen), rc1, fmt1); Rectangle rc2 = new Rectangle(0, 0, 120, 20); StringFormat fmt2 = new StringFormat(); fmt2.Alignment = StringAlignment.Center; ig.TranslateTransform(30, 160); ig.RotateTransform(90); ig.DrawRectangle(new Pen(Color.Blue), rc2); ig.DrawString("Text...2", fnt2, new SolidBrush(Color.DarkGreen), rc2, fmt2); ig.ResetTransform(); Rectangle rc3 = new Rectangle(30, 90, 300, 30); StringFormat fmt3 = new StringFormat(); fmt3.Alignment = StringAlignment.Far; ig.DrawRectangle(new Pen(Color.Blue), rc3); ig.DrawString("Text...3", fnt3, new SolidBrush(Color.DarkGreen), rc3, fmt3); //measurestring const string mme = "MeasureString Is Impossible To Emulate"; SizeF siz = ig.MeasureString(mme, fnt1); ig.DrawRectangle(new Pen(Color.Red), 20, 200, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, 150); ig.DrawRectangle(new Pen(Color.Orange), 20, 230, siz.Width, siz.Height); siz = ig.MeasureString(mme, fnt1, new SizeF(150, 150), new StringFormat(StringFormatFlags.DirectionVertical)); ig.DrawRectangle(new Pen(Color.Yellow), 20, 200, siz.Width, siz.Height); } else if (s == "Rect-aligned Text") { ig.Clear(Color.White); ig.ScaleTransform( (float)panel1.ClientSize.Width / RectAlignedTextTest.CanvasSize, (float)panel1.ClientSize.Height / RectAlignedTextTest.CanvasSize); RectAlignedTextTest.DrawTest(ig); } else if (s == "Images") { Icon ike = new Icon(GetType(), "App.ico"); ig.DrawIcon(ike, 10, 10); //ig.DrawIcon(ike, new Rectangle(270, 400, 30, 40)); Bitmap bmp = new Bitmap(GetType(), "test.bmp"); ig.DrawImage(bmp, 100f, 150f); GraphicsContainer cnt = ig.BeginContainer(); ig.RotateTransform(5); ig.DrawImage(bmp, 160f, 50f, 120f, 70f); ig.EndContainer(cnt); //ig.DrawImageUnscaled(bmp, 270, 450, 20, 20); } else if (s == "Path") { /* The following example GraphicsPath code comes from the MSDN docs on the GraphicsPathIterator class * https://msdn.microsoft.com/en-us/library/79k451ts.aspx * */ // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, an ellipse, and 2 markers. myPath.AddLines(myPoints); myPath.SetMarkers(); myPath.AddRectangle(myRect); myPath.SetMarkers(); myPath.AddEllipse(220, 220, 100, 100); ig.DrawPath(new Pen(Color.Black), myPath); LinearGradientBrush gbr2 = new LinearGradientBrush(new Point(0, 0), new Point(10, 20), Color.WhiteSmoke, Color.CornflowerBlue); gbr2.WrapMode = WrapMode.TileFlipXY; ig.FillPath(gbr2, myPath); GraphicsPath myPath2 = new GraphicsPath(); myPath2.AddLine(100, 100, 130, 120); myPath2.AddEllipse(120, 120, 120, 140); myPath2.AddBezier(130, 160, 170, 160, 150, 130, 200, 110); ig.DrawPath(new Pen(Color.Blue), myPath2); } else if (s == "Path 2 (Slow)") { SolidBrush mySolidBrush = new SolidBrush(Color.Aqua); GraphicsPath myGraphicsPath = new GraphicsPath(); Point[] myPointArray = { new Point(15, 20), new Point(20, 40), new Point(50, 30) }; FontFamily myFontFamily = new FontFamily("Times New Roman"); PointF myPointF = new PointF(50, 20); StringFormat myStringFormat = new StringFormat(); myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180); myGraphicsPath.AddCurve(myPointArray); myGraphicsPath.AddString("a string in a path filled", myFontFamily, 0, 24, myPointF, myStringFormat); myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110); ig.FillPath(mySolidBrush, myGraphicsPath); ig.DrawPath(new Pen(Color.Green), myGraphicsPath); } else { throw new NotImplementedException(); } }
private GraphicsPath TextPath(string s, Font f, Rectangle r) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Near; stringFormat.LineAlignment = StringAlignment.Near; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddString(s, f.FontFamily, (int)f.Style, f.Size, r, stringFormat); return graphicsPath; }
/// <summary> /// /// </summary> /// <param name="fontFamily"></param> /// <param name="size"></param> /// <returns></returns> private static List <GlyphPolygons> GenerateGlyphs(FontFamily fontFamily, uint size, FontStyle fontStyle) { List <GlyphPolygons> glyphs = new List <GlyphPolygons>(); using (Bitmap bitmap = new Bitmap(1, 1)) using (Graphics g = Graphics.FromImage(bitmap)) using (System.Drawing.Font font = new System.Drawing.Font(fontFamily, size, fontStyle)) using (GraphicsPath graphicsPath = new GraphicsPath()) { StringFormat stringFormat = StringFormat.GenericTypographic; // Avoid grid fitting g.TextRenderingHint = TextRenderingHint.AntiAlias; System.Drawing.Drawing2D.Matrix gPathMatrix = new System.Drawing.Drawing2D.Matrix(); gPathMatrix.Translate(0.0f, size); gPathMatrix.Scale(+1.25f, -1.25f); // Note: GraphicsPath is currently giving path points smaller than // the equivalent texture font. graphicsPath.FillMode = FillMode.Winding; foreach (char c in GetFontCharacters()) { graphicsPath.AddString(c.ToString(), fontFamily, (int)fontStyle, size, new PointF(0, 0), stringFormat); graphicsPath.Flatten(); graphicsPath.Transform(gPathMatrix); List <List <Vertex2f> > vCountours = new List <List <Vertex2f> >(); try { PointF[] gPoints = graphicsPath.PathPoints; byte[] gPathTypes = graphicsPath.PathTypes; List <Vertex2f> vCountour = null; int vCountourStartIndex = 0; for (int i = 0; i < gPoints.Length; i++) { switch (gPathTypes[i] & 0x07) { case 0: vCountour = new List <Vertex2f>(); vCountourStartIndex = i; continue; case 1: if (vCountour == null) { throw new InvalidOperationException("no start point"); } vCountour.Add(new Vertex2f(gPoints[i].X, gPoints[i].Y)); break; default: throw new NotSupportedException(); } if ((gPathTypes[i] & 0x80) != 0) { vCountour.Add(new Vertex2f(gPoints[vCountourStartIndex].X, gPoints[vCountourStartIndex].Y)); vCountours.Add(vCountour); } } } catch (Exception) { vCountours.Clear(); } SizeF cSize; switch (c) { case ' ': cSize = g.MeasureString(c.ToString(), font, 0, StringFormat.GenericDefault); break; default: cSize = g.MeasureString(c.ToString(), font, 0, stringFormat); break; } glyphs.Add(new GlyphPolygons(c, cSize, vCountours)); graphicsPath.Reset(); } } return(glyphs); }
// ==================================================================== // Creates the bitmap image. // ==================================================================== private void GenerateImage() { // Set up the text font. //SizeF size; float fontSize = 14; Font font; font = new Font(this.familyName, fontSize, FontStyle.Regular); // Declare a proposed size with dimensions set to the maximum integer value. Size proposedSize = new Size(int.MaxValue, int.MaxValue); Bitmap bitmap2 = new Bitmap(width, height, PixelFormat.Format32bppArgb); Graphics g2 = Graphics.FromImage(bitmap2); g2.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, width + 1, (int)height + 1); // Fill in the background. g2.FillRectangle(Brushes.White, rect); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); g2.FillPath(Brushes.Black, path); // Clean up. font.Dispose(); g2.Dispose(); // Set the image. this.image = bitmap2; }
/// <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 SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> DrawPrivateFont(string drawstr, DrawMode drawmode, Color fontColor, Color edgeColor, Color gradationTopColor, Color gradationBottomColor, int edge_Ratio) { if (this._fontfamily == null || drawstr == null || drawstr == "" || drawstr == " " || 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 SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32>(1, 1)); } // 描画サイズを測定する Size stringSize; using (Bitmap bmptmp = new Bitmap(1, 1)) { using (Graphics gtmp = Graphics.FromImage(bmptmp)) { gtmp.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; using (StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Far, // 画面下部(垂直方向位置) Alignment = StringAlignment.Center, // 画面中央(水平方向位置) FormatFlags = StringFormatFlags.NoWrap, // どんなに長くて単語の区切りが良くても改行しない (AioiLight) Trimming = StringTrimming.None, // どんなに長くてもトリミングしない (AioiLight) }) { //float to int SizeF fstringSize = gtmp.MeasureString(drawstr, this._font, new PointF(0, 0), sf); stringSize = new Size((int)fstringSize.Width, this._font.Height); stringSize.Width += 10; //2015.04.01 kairera0467 ROTTERDAM NATIONの描画サイズがうまくいかんので。 } } } bool bEdge = ((drawmode & DrawMode.Edge) == DrawMode.Edge); bool bGradation = ((drawmode & DrawMode.Gradation) == DrawMode.Gradation); // 縁取りの縁のサイズは、とりあえずフォントの大きさの(1/SkinConfig)とする int nEdgePt = (bEdge) ? (10 * _pt / edge_Ratio) : 0; //SkinConfigにて設定可能に(rhimm) //取得した描画サイズを基に、描画先のbitmapを作成する Bitmap bmp = new Bitmap(stringSize.Width + nEdgePt * 2, stringSize.Height + nEdgePt * 2); bmp.MakeTransparent(); using (Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // レイアウト枠 Rectangle r = new Rectangle(0, 0, stringSize.Width + nEdgePt * 2 + (Text_Correction_X * stringSize.Width / 100), stringSize.Height + nEdgePt * 2 + (Text_Correction_Y * stringSize.Height / 100)); if (bEdge) // 縁取り有りの描画 { using (StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Far, // 画面下部(垂直方向位置) Alignment = StringAlignment.Center, // 画面中央(水平方向位置) FormatFlags = StringFormatFlags.NoWrap, // どんなに長くて単語の区切りが良くても改行しない (AioiLight) Trimming = StringTrimming.None, // どんなに長くてもトリミングしない (AioiLight) }) { // DrawPathで、ポイントサイズを使って描画するために、DPIを使って単位変換する // (これをしないと、単位が違うために、小さめに描画されてしまう) float sizeInPixels = _font.SizeInPoints * g.DpiY / 72; // 1 inch = 72 points GraphicsPath gp = new GraphicsPath(); gp.AddString(drawstr, this._fontfamily, (int)this._font.Style, sizeInPixels, r, sf); // 縁取りを描画する Pen p = new Pen(edgeColor, nEdgePt); p.LineJoin = 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 { // 縁取りなしの描画 g.DrawString(drawstr, _font, new SolidBrush(fontColor), new PointF(0, 0)); } _rectStrings = new Rectangle(0, 0, stringSize.Width, stringSize.Height); _ptOrigin = new Point(nEdgePt * 2, nEdgePt * 2); } return(CConvert.ToImageSharpImage(bmp)); }
private void GenerateImage() { Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bitmap); graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rectangle = new Rectangle(0, 0, Width, Height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.DashedUpwardDiagonal, Color.LightGray, Color.White); graphics.FillRectangle(hatchBrush, rectangle); float num = (float)(rectangle.Height + 1); //Font font=new Font(new FontFamily("Times New Roman"), FontSize, FontStyle.Bold); //do //{ // num -= 1f; // font = new Font(new FontFamily("Times New Roman"), num, FontStyle.Bold); //} //while (num > rectangle.Height - 10); //(graphics.MeasureString(Code, font).Width > (float)rectangle.Width); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddString(Code, new FontFamily("Times New Roman"), (int)FontStyle.Bold, FontSize, rectangle, stringFormat); float num2 = 4f; PointF[] destPoints = new PointF[] { new PointF((float)random.Next(rectangle.Width) / num2, (float)random.Next(rectangle.Height) / num2), new PointF((float)rectangle.Width - (float)random.Next(rectangle.Width) / num2, (float)random.Next(rectangle.Height) / num2), new PointF((float)random.Next(rectangle.Width) / num2, (float)rectangle.Height - (float)random.Next(rectangle.Height) / num2), new PointF((float)rectangle.Width - (float)random.Next(rectangle.Width) / num2, (float)rectangle.Height - (float)random.Next(rectangle.Height) / num2) }; Matrix matrix = new Matrix(); matrix.Translate(0f, 0f); graphicsPath.Warp(destPoints, rectangle, matrix, WarpMode.Perspective, 0.5f); //hatchBrush = new HatchBrush(HatchStyle.Percent20, Color.Yellow, Color.Green); Color[] colors = { Color.Red, Color.Blue, Color.Green, Color.MediumTurquoise, Color.Black, Color.Navy, Color.Indigo, Color.Purple, Color.DarkRed, Color.DarkBlue }; int clen = colors.Length; LinearGradientBrush brush = new LinearGradientBrush(rectangle, colors[new Random().Next(clen)], colors[new Random(DateTime.Now.Second).Next(clen)], LinearGradientMode.Horizontal); brush.SetSigmaBellShape(Convert.ToSingle(new Random().NextDouble())); graphics.FillPath(brush, graphicsPath); //if (QJGL) //{ // int num3 = Math.Max(rectangle.Width, rectangle.Height); // for (int i = 0; i < (int)((float)(rectangle.Width * rectangle.Height) / 30f); i++) // { // int x = random.Next(rectangle.Width); // int y = random.Next(rectangle.Height); // int num4 = random.Next(num3 / 50); // int num5 = random.Next(num3 / 50); // graphics.FillEllipse(hatchBrush, x, y, num4, num5); // } //} hatchBrush.Dispose(); graphics.Dispose(); image = TwistImage(bitmap, true, new Random().Next(3), new Random().NextDouble() * 2 * 3.14); }
/// <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 SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32> DrawPrivateFont_V(string drawstr, DrawMode drawMode, Color fontColor, Color edgeColor, int edge_Ratio) { if (this._fontfamily == null || drawstr == null || drawstr == "" || drawstr == " " || 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 SixLabors.ImageSharp.Image <SixLabors.ImageSharp.PixelFormats.Rgba32>(1, 1)); } drawstr = drawstr.Replace("・", "."); 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; using (Bitmap bmptmp = new Bitmap(1, 1)) { using (Graphics gtmp = Graphics.FromImage(bmptmp)) { using ( StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Far, // 画面下部(垂直方向位置) Alignment = StringAlignment.Center, // 画面中央(水平方向位置) FormatFlags = StringFormatFlags.NoWrap, // どんなに長くて単語の区切りが良くても改行しない (AioiLight) Trimming = StringTrimming.None, // どんなに長くてもトリミングしない (AioiLight) }) { //float to int SizeF fstringSize = gtmp.MeasureString(strName[i], this._font, new PointF(0, 0), sf); strSize = new Size((int)fstringSize.Width, (int)fstringSize.Height); } } } //stringformatは最初にやっていてもいいだろう。 using (StringFormat sFormat = new StringFormat() { LineAlignment = StringAlignment.Center, // 画面下部(垂直方向位置) Alignment = StringAlignment.Center, // 画面中央(水平方向位置) }) { //できるだけ正確な値を計算しておきたい...! Rectangle rect正確なサイズ = this.MeasureStringPrecisely(strName[i], strSize, sFormat, edge_Ratio); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; 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) + 2; } else if (strName[i] == "_") { nHeight += (rect正確なサイズ.Height) + 2; } else if (strName[i] == " ") { nHeight += (6); } else { nHeight += (rect正確なサイズ.Height) + 2; } } } #endregion Bitmap bmpCambus = new Bitmap(46, nHeight); using (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 -= 2; } for (int i = 0; i < strName.Length; i++) { Size strSize; using (Bitmap bmptmp = new Bitmap(1, 1)) { using (Graphics gtmp = Graphics.FromImage(bmptmp)) { using ( StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Far, // 画面下部(垂直方向位置) Alignment = StringAlignment.Center, // 画面中央(水平方向位置) FormatFlags = StringFormatFlags.NoWrap, // どんなに長くて単語の区切りが良くても改行しない (AioiLight) Trimming = StringTrimming.None, // どんなに長くてもトリミングしない (AioiLight) }) { //float to int SizeF fstringSize = gtmp.MeasureString(strName[i], this._font, new PointF(0, 0), sf); strSize = new Size((int)fstringSize.Width, (int)fstringSize.Height); } } } //stringformatは最初にやっていてもいいだろう。 StringFormat sFormat = new StringFormat() { LineAlignment = StringAlignment.Center, // 画面下部(垂直方向位置) Alignment = StringAlignment.Near, // 画面中央(水平方向位置) }; //できるだけ正確な値を計算しておきたい...! Rectangle rect正確なサイズ = this.MeasureStringPrecisely(strName[i], strSize, sFormat, edge_Ratio); int n余白サイズ = strSize.Height - rect正確なサイズ.Height; Bitmap bmpV = new Bitmap((rect正確なサイズ.Width + 6) + nAdded, (rect正確なサイズ.Height) + 6); bmpV.MakeTransparent(); Graphics gV = Graphics.FromImage(bmpV); gV.SmoothingMode = SmoothingMode.HighQuality; if (CorrectionX_Chara_List_Vertical != null && CorrectionX_Chara_List_Value_Vertical != null) { int Xindex = Array.IndexOf(CorrectionX_Chara_List_Vertical, strName[i]); if (-1 < Xindex && Xindex < CorrectionX_Chara_List_Value_Vertical.Length && CorrectionX_Chara_List_Vertical.Contains(strName[i])) { nEdge補正X = CorrectionX_Chara_List_Value_Vertical[Xindex]; } else { if (-1 < Xindex && CorrectionX_Chara_List_Value_Vertical.Length <= Xindex && CorrectionX_Chara_List_Vertical.Contains(strName[i])) { nEdge補正X = CorrectionX_Chara_List_Value_Vertical[0]; } else { nEdge補正X = 0; } } } if (CorrectionY_Chara_List_Vertical != null && CorrectionY_Chara_List_Value_Vertical != null) { int Yindex = Array.IndexOf(CorrectionY_Chara_List_Vertical, strName[i]); if (-1 < Yindex && Yindex < CorrectionY_Chara_List_Value_Vertical.Length && CorrectionY_Chara_List_Vertical.Contains(strName[i])) { nEdge補正Y = CorrectionY_Chara_List_Value_Vertical[Yindex]; } else { if (-1 < Yindex && CorrectionY_Chara_List_Value_Vertical.Length <= Yindex && CorrectionY_Chara_List_Vertical.Contains(strName[i])) { nEdge補正Y = CorrectionY_Chara_List_Value_Vertical[0]; } else { nEdge補正Y = 0; } } } //X座標、Y座標それぞれについて、SkinConfig内でズレを直したい文字を , で区切って列挙して、 //補正値を記入することで、特定のそれらの文字について一括で座標をずらす。 //現時点では補正値をX,Y各座標について1個ずつしか取れない(複数対1)ので、 //文字を列挙して、同じ数だけそれぞれの文字の補正値を記入できるような枠組をつくりたい。(20181205 rhimm)←実装済み //2020.05.04 Mr-Ojii 文字ごとに補正をかけられるように。「,」区切りで書けるように。 Rectangle rect = new Rectangle(-3 - nAdded + (nEdge補正X * _pt / 100), -rect正確なサイズ.Y - 2 + (nEdge補正Y * _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 / 72f; // 1 inch = 72 points GraphicsPath gpV = new GraphicsPath(); gpV.AddString(strName[i], this._fontfamily, (int)this._font.Style, sizeInPixels, rect, sFormat); // 縁取りを描画する //int nEdgePt = (_pt / 3); // 縁取りをフォントサイズ基準に変更 float nEdgePt = (10f * _pt / edge_Ratio); // SkinConfigにて設定可能に(rhimm) Pen pV = new Pen(edgeColor, nEdgePt); pV.LineJoin = LineJoin.Round; gV.DrawPath(pV, gpV); // 塗りつぶす Brush brV = new SolidBrush(fontColor); gV.FillPath(brV, gpV); if (brV != null) { brV.Dispose(); } if (pV != null) { pV.Dispose(); } if (gpV != null) { gpV.Dispose(); } if (gV != null) { gV.Dispose(); } 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 (Rotate_Chara_List_Vertical.Contains(strName[i])) { bmpV.RotateFlip(RotateFlipType.Rotate90FlipNone); } //個別の文字に関して、カンマで区切ってSkinConfigに記入したものを回転させる(20181205 rhimm) else if (strName[i] == " ") { nNowPos += 10; } 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(); } _rectStrings = new Rectangle(0, 0, strSize.Width, strSize.Height); _ptOrigin = new Point(6 * 2, 6 * 2); } } return(CConvert.ToImageSharpImage(bmpCambus)); }
/// <summary> /// 生成一页的字库图像数据 /// </summary> private Bitmap CreateFontImagePage(List <byte[]> imageData, List <CwdhEntries> newCwdhEntriesList, List <string> unicodeCharList, ref int unicodeCharIndex) { // 单个子对齐风格 StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Near; CharacterRange[] characterRanges = { new CharacterRange(0, 1) }; sf.SetMeasurableCharacterRanges(characterRanges); RectangleF rectangle; FontFamily family = new FontFamily(txtFontTest.Font.Name); Pen blackPen = new Pen(Color.Black, 1); // 图片 Bitmap bmp = new Bitmap(this.oldFontInfo.ImageWidth, this.oldFontInfo.ImageHeight); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.FromArgb(0, 0xFF, 0xFF, 0xFF)); // 字符相关属性 // 字符的宽度 int charWidth; // 字符左边距离边框的距离 int charLeftWidth; for (int y = 0; y < this.oldFontInfo.CharactersPerColumn; y++) { for (int x = 0; x < this.oldFontInfo.CharactersPerRow; x++) { this.ProcessBarStep(); if (unicodeCharIndex >= unicodeCharList.Count) { break; } string strCurrentChar = unicodeCharList[unicodeCharIndex]; if (!string.Empty.Equals(strCurrentChar)) { // 在指定的区域内写入特定汉字 rectangle = new RectangleF(x * (this.oldFontInfo.CellWidth + 1), y * (this.oldFontInfo.CellHeight + 1), this.oldFontInfo.CellWidth + 1, this.oldFontInfo.CellHeight + 1); GraphicsPath graphPath = new GraphicsPath(); graphPath.AddString(strCurrentChar, family, (int)FontStyle.Bold, this.oldFontInfo.CellHeight, rectangle, sf); // 为了实现图像里面是白色,边框是黑色,真是费了一番脑筋 // 下面是最后的方案,过程真是艰辛,结果还真简单 g.FillPath(Brushes.White, graphPath); g.DrawPath(blackPen, graphPath); Region[] charRegions = g.MeasureCharacterRanges(strCurrentChar, txtFontTest.Font, rectangle, sf); charWidth = (int)charRegions[0].GetBounds(g).Width; if (string.Empty.Equals(strCurrentChar.Trim())) { newCwdhEntriesList.Add(new CwdhEntries(13, 0, 13)); } else { // 为了理解和计算CwdhEntries的三个参数,也是花费了一番周折 // 第一个参数:应该是Left padding,离前一个字符的距离 // 第二个参数:显示字符时,从当前字符图片中,取得的宽度 // 第一个参数:显示字符时,这个字符占的宽度 charLeftWidth = (this.oldFontInfo.CellWidth + 1 - charWidth) / 2 + 1; if (charLeftWidth < 0) { charLeftWidth = 0; } charWidth += charLeftWidth; newCwdhEntriesList.Add( new CwdhEntries(0, charWidth, charWidth + 1)); } } unicodeCharIndex++; } } imageData.Add(Util.ImageEncode(bmp, Util.GetImageFormat(this.oldFontInfo.ImageFormat))); return(bmp); }
protected override void OnPaint(GUI.PaintEventArgs e) { base.OnPaint(e); Graphics graphics = e.Graphics; graphics.SmoothingMode = SmoothingMode.AntiAlias; PolarTransform polarTransform = new PolarTransform(); polarTransform.FullCircle = -600; polarTransform.BaseScale = -1; polarTransform.SetBaseOffset(0, m_BaseYSlider.Value); polarTransform.SetTranslation(ClientWidth / 2.0, ClientHeight / 2.0 - 30.0); polarTransform.Spiral = m_SpiralSlider.Value; // Draw Background RectangleGeometry borderGeometry = new RectangleGeometry(0, 0, m_TextBox.Width, m_TextBox.Height); // Just for little optimization GeometrySegmentator borderGeometrySegmentator = new GeometrySegmentator(borderGeometry); GeometryTransformer borderGeometrySegmentatorPolarTransformer = new GeometryTransformer(borderGeometrySegmentator, polarTransform); graphics.FillGeometry(Color.WhiteSmoke, borderGeometrySegmentatorPolarTransformer); // Selection if (m_TextBox.HasSelectionAndVisible) { RectangleGeometry selectionGeometry = new RectangleGeometry(m_TextBox.SelectionBounds // Just to prevent some artefacts - new PointI(0, 1) + new SizeI(0, 2)); FillGeometry(graphics, polarTransform, m_TextBox.SelectionColor, selectionGeometry); } // Caret if (m_TextBox.IsCaretVisible) { RectangleGeometry caretGeometry = new RectangleGeometry(m_TextBox.CaretBounds); FillGeometry(graphics, polarTransform, Color.Black, caretGeometry); } // Draw Border graphics.DrawGeometry(Color.DodgerBlue, borderGeometrySegmentatorPolarTransformer, 2); // Text Font font = m_TextBox.Font; GraphicsPath textGeometry = new GraphicsPath(); textGeometry.AddString( m_TextBox.Text, font.FontFamily, font.Style, font.Size * 96.0 / 72.0, new Point(4, 1), StringFormat.GenericTypographic); FlattenCurveGeometry textFlattenGeometry = new FlattenCurveGeometry(textGeometry); // Need for clip text Geometry clippedTextFlattenGeometry = new FlattenCurveGeometry( new CombinedGeometry(textFlattenGeometry, new RectangleGeometry(1, 1, m_TextBox.Width - 2, m_TextBox.Height - 2), CombinedGeometry.CombineMode.And)); FillGeometry(graphics, polarTransform, m_TextBox.TextColor, clippedTextFlattenGeometry); }
private Bitmap GenerateImagePrivate() { RectangleF rectF; Rectangle rect; SizeF ef1; Font font1; Bitmap bitmap1 = new Bitmap(_intWidth, _intHeight, PixelFormat.Format32bppArgb); Graphics graphics1 = Graphics.FromImage(bitmap1); graphics1.SmoothingMode = SmoothingMode.AntiAlias; rectF = new RectangleF(0, 0, _intWidth, _intHeight); rect = new Rectangle(0, 0, _intWidth, _intHeight); HatchBrush brush1 = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); graphics1.FillRectangle(brush1, rect); float prevWidth = 0; float fsize = Convert.ToInt32(_intHeight * 0.8); do { font1 = new Font(_strFontFamilyName, fsize, FontStyle.Bold); ef1 = graphics1.MeasureString(this.Text, font1); // -- does our text fit in the rect? if (ef1.Width <= _intWidth) { break; } // -- doesn't fit in the rect, scale font down and try again. if (prevWidth > 0) { int intEstSize = Convert.ToInt32((ef1.Width - _intWidth) / (double)(prevWidth - ef1.Width)); if (intEstSize > 0) { fsize = fsize - intEstSize; } else { fsize -= 1; } } else { fsize -= 1; } prevWidth = ef1.Width; }while (true); // -- the resulting font size is usally conservative, so bump it up a few sizes. fsize += 4; font1 = new Font(_strFontFamilyName, fsize, FontStyle.Bold); // -- get our textpath for the given font/size combo StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; GraphicsPath textPath = new GraphicsPath(); textPath.AddString(this.Text, font1.FontFamily, System.Convert.ToInt32(font1.Style), font1.Size, rect, sf); // -- are we warping the text? if (this.FontWarp != FontWarpFactor.None) { int intWarpDivisor = 6; switch (_fontWarp) { case FontWarpFactor.Low: { intWarpDivisor = 6; break; } case FontWarpFactor.Medium: { intWarpDivisor = 5; break; } case FontWarpFactor.High: { intWarpDivisor = 4; break; } case FontWarpFactor.Extreme: { intWarpDivisor = 3; break; } } int intHrange; int intWrange; int intMin; int intMin3; intHrange = Convert.ToInt32(rect.Height / (double)intWarpDivisor); intWrange = Convert.ToInt32(rect.Width / (double)intWarpDivisor); intMin = 0; PointF p1 = RandomPoint(0, intWrange, ref intMin, ref intHrange); PointF p2 = RandomPoint(rect.Width - (intWrange - Convert.ToInt32(p1.X)), rect.Width, ref intMin, ref intHrange); intMin3 = rect.Height - (intHrange - Convert.ToInt32(p1.Y)); intHrange = rect.Height; PointF p3 = RandomPoint(0, intWrange, ref intMin3, ref intHrange); intMin3 = rect.Height - (intHrange - Convert.ToInt32(p2.Y)); PointF p4 = RandomPoint(rect.Width - (intWrange - Convert.ToInt32(p3.X)), rect.Width, ref intMin3, ref intHrange); PointF[] points = new PointF[] { p1, p2, p3, p4 }; Matrix m = new Matrix(); m.Translate(0, 0); textPath.Warp(points, rectF, m, WarpMode.Perspective, 0); } // -- write our (possibly warped) text brush1 = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); graphics1.FillPath(brush1, textPath); // -- add noise to image int intMaxDim = Math.Max(rect.Width, rect.Height); int i; for (i = 0; i <= Convert.ToInt32(((rect.Width * rect.Height) / (double)30)); i++) { graphics1.FillEllipse(brush1, _rand.Next(rect.Width), _rand.Next(rect.Height), _rand.Next(Convert.ToInt32(intMaxDim / (double)50)), _rand.Next(Convert.ToInt32(intMaxDim / (double)50))); } // -- it's important to clean up unmanaged resources font1.Dispose(); brush1.Dispose(); graphics1.Dispose(); return(bitmap1); }
private void buttonCreateMeme_Click(object sender, RoutedEventArgs e) { var meme = new Meme(); meme.textTop.Text = TopText; meme.textBottom.Text = BottomText; meme.Owner = this; meme.ShowDialog(); if (String.IsNullOrWhiteSpace(TopText) && String.IsNullOrWhiteSpace(BottomText)) { return; } var fontFamily = System.Drawing.FontFamily.Families.FirstOrDefault(ff => ff.Name == FontName); if (fontFamily == null) { fontFamily = System.Drawing.FontFamily.GenericSansSerif; } EditedImage = (Bitmap)OriginalImage.Clone(); Graphic = Graphics.FromImage(EditedImage); Graphic.SmoothingMode = SmoothingMode.AntiAlias; int pointSize = 1; Font font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); SizeF lastMeasurement = SizeF.Empty; System.Drawing.Point drawPoint = System.Drawing.Point.Empty; GraphicsPath path = new GraphicsPath(); if (!String.IsNullOrWhiteSpace(TopText)) { while (lastMeasurement.Width < SourceSize.Width - 25 && pointSize < Settings.Current.MemeMaxFontSize) { pointSize++; font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); lastMeasurement = Graphic.MeasureString(TopText, font); } pointSize--; font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); lastMeasurement = Graphic.MeasureString(TopText, font); drawPoint = new System.Drawing.Point((int)(SourceSize.Width / 2), 0); path = new GraphicsPath(); path.AddString(TopText, fontFamily, (int)System.Drawing.FontStyle.Bold, Graphic.DpiY * pointSize / 72, drawPoint, new StringFormat() { Alignment = StringAlignment.Center }); Graphic.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, pointSize / 4), path); Graphic.FillPath(System.Drawing.Brushes.White, path); pointSize = 1; font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); lastMeasurement = SizeF.Empty; } if (!String.IsNullOrWhiteSpace(BottomText)) { while (lastMeasurement.Width < SourceSize.Width - 25 && pointSize < Settings.Current.MemeMaxFontSize) { pointSize++; font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); lastMeasurement = Graphic.MeasureString(BottomText, font); } pointSize--; font = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold); lastMeasurement = Graphic.MeasureString(BottomText, font); drawPoint = new System.Drawing.Point((int)(SourceSize.Width / 2), (int)SourceSize.Height - (int)lastMeasurement.Height); path = new GraphicsPath(); path.AddString(BottomText, fontFamily, (int)System.Drawing.FontStyle.Bold, Graphic.DpiY * pointSize / 72, drawPoint, new StringFormat() { Alignment = StringAlignment.Center }); Graphic.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, pointSize / 4), path); Graphic.FillPath(System.Drawing.Brushes.White, path); } Graphic.Save(); using (var ms = new MemoryStream()) { EditedImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ImageSourceFrame = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); imageMain.Source = ImageSourceFrame; } }
private void Bitdefender_DrawControlBox(Graphics G) { G.SmoothingMode = SmoothingMode.HighQuality; G.FillPath(Bitdefender_LGB2, Bitdefender_GP3); G.DrawPath(Bitdefender_P3, Bitdefender_GP3); G.DrawPath(Bitdefender_P4, Bitdefender_GP4); //#Zone " If you want white line " G.DrawLine(Bitdefender_P2, Bitdefender_R5.Left, Bitdefender_R5.Top + 1, Bitdefender_R5.Right, Bitdefender_R5.Top + 1); //#End Zone //#Zone " Fix !important " G.DrawLine(Bitdefender_P3, Bitdefender_R5.Right, Bitdefender_R5.Top, Bitdefender_R5.Right, Bitdefender_R5.Bottom - 4); G.DrawLine(Bitdefender_P4, Bitdefender_R6.Right, Bitdefender_R6.Top + 1, Bitdefender_R6.Right, Bitdefender_R6.Bottom - 4); G.SmoothingMode = SmoothingMode.Default; G.FillRectangle(Bitdefender_P3.Brush, new Rectangle(Bitdefender_R5.X, Bitdefender_R5.Y + 1, 1, 1)); G.FillRectangle(Bitdefender_P3.Brush, new Rectangle(Bitdefender_R5.Right, Bitdefender_R5.Top + 1, 1, 1)); //#End Zone //#Zone " First line " G.DrawLine(Bitdefender_P5, Bitdefender_R5.Left + 29, Bitdefender_R5.Top + 2, Bitdefender_R5.Left + 29, Bitdefender_R5.Bottom - 2); G.DrawLine(Bitdefender_P6, Bitdefender_R5.Left + 30, Bitdefender_R5.Top + 2, Bitdefender_R5.Left + 30, Bitdefender_R5.Bottom - 2); //#End Zone //#Zone " Second line " G.DrawLine(Bitdefender_P5, Bitdefender_R5.Left + 56, Bitdefender_R5.Top + 2, Bitdefender_R5.Left + 56, Bitdefender_R5.Bottom - 2); G.DrawLine(Bitdefender_P6, Bitdefender_R5.Left + 57, Bitdefender_R5.Top + 2, Bitdefender_R5.Left + 57, Bitdefender_R5.Bottom - 2); //#End Zone //#Zone " close string " Bitdefender_controlboxPath.AddString("r", new FontFamily("Webdings"), Convert.ToInt32(FontStyle.Regular), 15, new Point(Right - Bitdefender_Padding - (Bitdefender_btnSize.Width + 20) + 2, Bitdefender_Padding + 8), null); G.FillPath(Brushes.White, Bitdefender_controlboxPath); G.DrawPath(Pens.Black, Bitdefender_controlboxPath); //#End Zone //#Zone " max string " switch (Parent.FindForm().WindowState) { case FormWindowState.Maximized: Bitdefender_controlboxPath.AddString("2", new FontFamily("Webdings"), Convert.ToInt32(FontStyle.Regular), 15, new Point(Right - Bitdefender_Padding - (Bitdefender_btnSize.Width * 2 + 20) + 4, Bitdefender_Padding + 8), null); G.DrawPath(Pens.Black, Bitdefender_controlboxPath); G.FillPath(Brushes.White, Bitdefender_controlboxPath); break; case FormWindowState.Normal: Bitdefender_controlboxPath.AddString("1", new FontFamily("Webdings"), Convert.ToInt32(FontStyle.Bold), 15, new Point(Right - Bitdefender_Padding - (Bitdefender_btnSize.Width * 2 + 20) + 2, Bitdefender_Padding + 8), null); G.DrawPath(Pens.Black, Bitdefender_controlboxPath); G.FillPath(Brushes.White, Bitdefender_controlboxPath); break; } //#End Zone //#Zone " min string " Bitdefender_controlboxPath.AddString("0", new FontFamily("Webdings"), Convert.ToInt32(FontStyle.Bold), 15, new Point(Right - Bitdefender_Padding - (Bitdefender_btnSize.Width * 3 + 20) + 2, Bitdefender_Padding + 8), null); G.DrawPath(Pens.Black, Bitdefender_controlboxPath); G.FillPath(Brushes.White, Bitdefender_controlboxPath); //#End Zone }
public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat format) { Changed(); gdiPath.AddString(s, family, style, emSize, origin, format); }
public void DrawText(Graphics zGraphics, ProjectLayoutElement zElement, string sInput, Brush zBrush, Font zFont, Color colorFont) { if (null == zFont) // default to something! { // font will show up in red if it's not yet set zFont = DrawItem.DefaultFont; zBrush = Brushes.Red; } var zFormat = new StringFormat { LineAlignment = zElement.GetVerticalAlignment(), Alignment = zElement.GetHorizontalAlignment() }; if (255 != zElement.opacity) { zBrush = new SolidBrush(Color.FromArgb(zElement.opacity, colorFont)); } if (zElement.autoscalefont) { SizeF zSize = zGraphics.MeasureString(sInput, zFont, new SizeF(zElement.width, int.MaxValue), zFormat); if (zSize.Height > zElement.height || zSize.Width > zElement.width) { float newSizeRatio; if ((zSize.Height - zElement.height) > (zSize.Width - zElement.width)) { newSizeRatio = (float)zElement.height / (float)zSize.Height; } else { newSizeRatio = (float)zElement.width / (float)zSize.Width; } var scaledFont = new Font(zFont.FontFamily, newSizeRatio * zFont.Size, zFont.Style); //Support.IO.Logger.AddLogLine(scaledFont.Size + " was [" + zFont.Size + "]"); zFont = scaledFont; #if true // the preprocessing above will get the font size close but not perfect, the slow code below further refines the size // slow mode - but perfect precision (well arguably with the Graphics.MeasureString) bool bUpscaled = false; if (0 < sInput.Trim().Length) { while (true) { zSize = zGraphics.MeasureString(sInput, zFont, new SizeF(zElement.width, int.MaxValue), zFormat); if (zSize.Height > zElement.height || zSize.Width > zElement.width) { if (zFont.Size == 1) { break; } zFont = new Font(zFont.FontFamily, zFont.Size - 1, zFont.Style); if (bUpscaled) { break; } } else { zFont = new Font(zFont.FontFamily, zFont.Size + 1, zFont.Style); bUpscaled = true; } } //Support.IO.Logger.AddLogLine("[" + zFont.Size + "]"); } #endif } // else -- font size is fine for this element } else { zFormat.Trimming = StringTrimming.EllipsisCharacter; } var fEmSize = zFont.Size; switch (zFont.Unit) { case GraphicsUnit.Point: fEmSize = zGraphics.DpiY * (zFont.Size / 72f); break; default: Logger.AddLogLine("This font is using the Unit: {0} (not currently supported)".FormatString(zFont.Unit.ToString())); break; } if (0 == zElement.outlinethickness) { try { zGraphics.DrawString(sInput, zFont, zBrush, new RectangleF(0, 0, zElement.width, zElement.height), zFormat); } catch (Exception) { Logger.AddLogLine("Unable to render text (font issue?)"); } } else { // prepare to draw text var zPath = new GraphicsPath(); try { zPath.AddString(sInput, zFont.FontFamily, (int)zFont.Style, fEmSize, new RectangleF(0, 0, zElement.width, zElement.height), zFormat); DrawItem.DrawOutline(zElement, zGraphics, zPath); } catch (Exception) { Logger.AddLogLine("Unable to render text (font issue?)"); } // fill in the outline zGraphics.FillPath(zBrush, zPath); } }
public override Bitmap Apply(Bitmap bmp) { if (string.IsNullOrEmpty(Text)) { return(bmp); } using (Font font = Font) { if (font == null || font.Size < 1) { return(bmp); } NameParser parser = new NameParser(NameParserType.Text); parser.ImageWidth = bmp.Width; parser.ImageHeight = bmp.Height; string parsedText = parser.Parse(Text); using (Graphics g = Graphics.FromImage(bmp)) using (GraphicsPath gp = new GraphicsPath()) { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.Half; gp.FillMode = FillMode.Winding; float emSize = g.DpiY * font.SizeInPoints / 72; gp.AddString(parsedText, font.FontFamily, (int)font.Style, emSize, Point.Empty, StringFormat.GenericDefault); if (Angle != 0) { using (Matrix matrix = new Matrix()) { matrix.Rotate(Angle); gp.Transform(matrix); } } RectangleF pathRect = gp.GetBounds(); if (pathRect.IsEmpty) { return(bmp); } Size textSize = pathRect.Size.ToSize(); Point textPosition = Helpers.GetPosition(Placement, Offset, bmp.Size, textSize); Rectangle textRectangle = new Rectangle(textPosition, textSize); if (AutoHide && !new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(textRectangle)) { return(bmp); } using (Matrix matrix = new Matrix()) { matrix.Translate(textRectangle.X - pathRect.X, textRectangle.Y - pathRect.Y); gp.Transform(matrix); } // Draw text shadow if (Shadow && ((!ShadowUseGradient && ShadowColor.A > 0) || (ShadowUseGradient && ShadowGradient.IsVisible))) { using (Matrix matrix = new Matrix()) { matrix.Translate(ShadowOffset.X, ShadowOffset.Y); gp.Transform(matrix); if (Outline && OutlineSize > 0) { if (ShadowUseGradient) { using (LinearGradientBrush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(OutlineSize + 1).LocationOffset(ShadowOffset))) using (Pen textShadowPen = new Pen(textShadowBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } else { using (Pen textShadowPen = new Pen(ShadowColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } } else { if (ShadowUseGradient) { using (Brush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(1).LocationOffset(ShadowOffset))) { g.FillPath(textShadowBrush, gp); } } else { using (Brush textShadowBrush = new SolidBrush(ShadowColor)) { g.FillPath(textShadowBrush, gp); } } } matrix.Reset(); matrix.Translate(-ShadowOffset.X, -ShadowOffset.Y); gp.Transform(matrix); } } // Draw text outline if (Outline && OutlineSize > 0) { if (OutlineUseGradient) { if (OutlineGradient.IsVisible) { using (LinearGradientBrush textOutlineBrush = OutlineGradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(OutlineSize + 1))) using (Pen textOutlinePen = new Pen(textOutlineBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } else if (OutlineColor.A > 0) { using (Pen textOutlinePen = new Pen(OutlineColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } // Draw text if (UseGradient) { if (Gradient.IsVisible) { using (Brush textBrush = Gradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(1))) { g.FillPath(textBrush, gp); } } } else if (Color.A > 0) { using (Brush textBrush = new SolidBrush(Color)) { g.FillPath(textBrush, gp); } } } return(bmp); } }
private void GenerateImage() { 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.Percent20, Color.Green, Color.White); g.FillRectangle(hatchBrush, rect); //HatchBrush hatchBrush1 = new HatchBrush(HatchStyle.Horizontal, Color.Red, Color.Transparent); //g.FillRectangle(hatchBrush1, rect); SizeF size; float fontSize = rect.Height + 10; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(Text, font); }while (size.Width > rect.Width); StringFormat format = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center, }; GraphicsPath path = new GraphicsPath(); path.AddString(Text, font.FontFamily, (int)font.Style, font.Size, rect, format); //path.AddString(this.Text, font.FontFamily, (int)font.Style, 75, rect, format); const float v = 9F; 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.NarrowHorizontal, Color.FromArgb(0, 0, 255, 0), Color.FromArgb(255, 255, 0, 0)); 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(); Image = bitmap; }
public void GenerateImage() { // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width + 20, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.Percent05, Color.FromArgb(230, 230, 230), Color.FromArgb(255, 255, 255)); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = this.height + 4; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(this.familyName, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > this.width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisPath; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size + 10, rect, format); float v = 4F; PointF[] points = { new PointF(random.Next(this.width) / v, random.Next(this.height) / v), new PointF(this.width - random.Next(this.width) / v, random.Next(this.height) / v), new PointF(random.Next(this.width) / v, this.height - random.Next(this.height) / v), new PointF(this.width - random.Next(this.width) / v, this.height - random.Next(this.height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(-5F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.Black, Color.Black); g.FillPath(hatchBrush, path); //// Add some random noise. int m = Math.Max(this.width, this.height); for (int i = 0; i < (int)(this.width * this.height) / 100; i++) { int x = random.Next(this.width); int y = random.Next(this.height); int w = random.Next(m / 25); int h = random.Next(m / 25); g.FillEllipse(hatchBrush, x, y, w, h); } // add line Pen pen = new Pen(Color.Black, 1); int qtPointLine = 7; PointF[] line = new PointF[qtPointLine]; for (int i = 0; i < qtPointLine; i++) { line[i].X = random.Next(this.width); line[i].Y = random.Next(this.height); } g.DrawBezier(pen, line[0], line[1], line[2], line[3]); g.DrawBezier(pen, line[3], line[4], line[5], line[6]); // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; }
// Create the corresponding GraphicsPath for the shape, and apply // it to the control by setting the Region property. private void RefreshPath() { path = new GraphicsPath(); patje = new GraphicsPath(); //switch (shape) //{ // case ShapeType.PosRectangle: path.AddRectangle(this.ClientRectangle); patje.AddString("POS1", new FontFamily("Arial"), (int)FontStyle.Regular, 10, new Point(4, 7), StringFormat.GenericDefault); // break; // case ShapeType.Ellipse: // path.AddEllipse(this.ClientRectangle); // break; // case ShapeType.Triangle: // Point pt1 = new Point(this.Width / 2, 0); // Point pt2 = new Point(0, this.Height); // Point pt3 = new Point(this.Width, this.Height); // path.AddPolygon(new Point[] { pt1, pt2, pt3 }); // break; //} this.Region = new Region(path); }
public void DrawText(string aText) { Graphics g = Graphics.FromImage(result); int startsize = Height; Font f = new Font("Verdana", startsize, FontStyle.Bold, GraphicsUnit.Pixel); do { f = new Font("Verdana", startsize, GraphicsUnit.Pixel); startsize--; } while ((g.MeasureString(aText, f).Width >= Width) || (g.MeasureString(aText, f).Height >= Height)); SizeF sf = g.MeasureString(aText, f); int width = Convert.ToInt32(sf.Width); int height = Convert.ToInt32(sf.Height); int x = Convert.ToInt32(Math.Abs((double)width - (double)Width) * rnd.NextDouble()); int y = Convert.ToInt32(Math.Abs((double)height - (double)Height) * rnd.NextDouble()); //////// Paths /// GraphicsPath path = new GraphicsPath(FillMode.Alternate); FontFamily family = new FontFamily("Verdana"); int fontStyle = (int)(FontStyle.Regular); float emSize = f.Size; Point origin = new Point(x, y); StringFormat format = StringFormat.GenericDefault; path.AddString(aText, family, fontStyle, emSize, origin, format); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; Rectangle rect = new Rectangle(0, 0, Width, Height); g.FillRectangle(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.White, 0f), rect); g.SmoothingMode = SmoothingMode.HighQuality; Color noiseCol = Color.FromArgb(100, 120, 180); Pen p = new Pen(noiseCol); /* generate random dots in background */ for( int i=0; i<(Width*Height)/3; i++ ) { g.FillEllipse(Brushes.Blue, rnd.Next(0, Width), rnd.Next(0, Height), 1, 1); } /*noise ends here*/ /* generate random lines in background */ for( int i=0; i<(Width*Height)/150; i++ ) { g.DrawLine(p,rnd.Next(0,Width), rnd.Next(0,Height), rnd.Next(0,Width), rnd.Next(0,Height)); } Color textColor = Color.FromArgb(20, 40, 100); g.FillPath(new SolidBrush(textColor), path); g.Dispose(); }
private void GenerateImage() { Bitmap bitmap = new Bitmap (this.width, this.height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.White, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(this.text, font.FontFamily, (int)font.Style, 30, rect, format); //float v = 4F; //PointF[] points = // { // new PointF(this.random.Next(rect.Width) / v, this.random.Next( // rect.Height) / v), // new PointF(rect.Width - this.random.Next(rect.Width) / v, // this.random.Next(rect.Height) / v), // new PointF(this.random.Next(rect.Width) / v, // rect.Height - this.random.Next(rect.Height) / v), // new PointF(rect.Width - this.random.Next(rect.Width) / v, // rect.Height - this.random.Next(rect.Height) / v) // }; //Matrix matrix = new Matrix(); //matrix.Translate(0F, 0F); //path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.CornflowerBlue); g.FillPath(hatchBrush, path); //int m = Math.Max(rect.Width, rect.Height); //for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) //{ // int x = this.random.Next(rect.Width); // int y = this.random.Next(rect.Height); // int w = this.random.Next(m / 50); // int h = this.random.Next(m / 50); // g.FillEllipse(hatchBrush, x, y, w, h); //} font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }
/* private void updateClock() { lblSongTime.Text = timeToString(coolProgressBar1.Value) + " / " + timeToString(coolProgressBar1.Maximum); lblSongTime.Refresh(); } */ private void RenderText(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; g.CompositingQuality = CompositingQuality.HighQuality; g.CompositingMode = CompositingMode.SourceOver; String text = valueToString(this.Value) + " / " + valueToString(this.Maximum); GraphicsPath stroke = new GraphicsPath(); stroke.AddString(text, this.Font.FontFamily, (int)FontStyle.Regular, this.Font.Size * 1.2f, new Point(0, 0), StringFormat.GenericDefault); RectangleF bounds = stroke.GetBounds(); /* Align right */ Matrix translationMatrix = new Matrix(); translationMatrix.Translate((this.Width - bounds.Width - 8) / 2, (this.Height - bounds.Height - 5) / 2); stroke.Transform(translationMatrix); g.DrawPath(new Pen(Brushes.Black, 3.0f), stroke); /* Stroke */ g.FillPath(Brushes.White, stroke); /* Text */ }
static Bitmap DrawBottom(string text) { var img = new Bitmap(ImageWidth, 150); Graphics g = Graphics.FromImage(img); g.SmoothingMode = SmoothingMode.HighQuality; PrivateFontCollection coll2 = new PrivateFontCollection(); coll2.AddFontFile(@"notoserifbk-subset.otf"); FontFamily bottomFontFamily = coll2.Families[0]; #region 欲しい! の描画 // 黒色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(5, 2), null); var pen = new Pen(Color.Black, 22) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 銀色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(5, 2), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 15, ImageWidth, 150), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(0, 15, 36), Color.FromArgb(0, 15, 36), Color.FromArgb(250, 250, 250), Color.FromArgb(150, 150, 150), Color.FromArgb(55, 58, 59), Color.FromArgb(25, 20, 31), Color.FromArgb(240, 240, 240), Color.FromArgb(166, 175, 194), Color.FromArgb(50, 50, 50), Color.FromArgb(50, 50, 50), }, Positions = new[] { 0, 0.15f, 0.28f, 0.35f, 0.55f, 0.65f, 0.72f, 0.75f, 0.8f, 1, } }; brush.InterpolationColors = blend; var pen = new Pen(brush, 19) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 黒色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(0, 0), null); var pen = new Pen(Color.FromArgb(16, 25, 58), 17) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 白 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(0, 0), null); var pen = new Pen(Color.FromArgb(221, 221, 221), 7) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 紺色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(0, 0), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 0, ImageWidth, 135), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(16, 25, 58), Color.FromArgb(16, 25, 58), Color.FromArgb(255, 255, 255), Color.FromArgb(16, 25, 58), Color.FromArgb(16, 25, 58), Color.FromArgb(16, 25, 58), }, Positions = new[] { 0, 0.23f, 0.26f, 0.28f, 0.37f, 1, } }; brush.InterpolationColors = blend; var pen = new Pen(brush, 7) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 銀色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, bottomFontFamily, 0, 100, new PointF(0, 0 - 3), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 0, ImageWidth, 135), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(245, 246, 248), Color.FromArgb(255, 255, 255), Color.FromArgb(195, 213, 220), Color.FromArgb(160, 190, 201), Color.FromArgb(160, 190, 201), Color.FromArgb(196, 215, 222), Color.FromArgb(255, 255, 255), Color.FromArgb(255, 255, 255), }, Positions = new[] { 0, 0.2f, 0.4f, 0.55f, 0.56f, 0.57f, 0.82f, 1, } }; brush.InterpolationColors = blend; g.FillPath(brush, graphiscPath); } #endregion var range = MeasureImage(img); return(img.Clone(new Rectangle(range.left, 0, range.right - range.left, img.Height), img.PixelFormat)); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; //g.Clear(Parent.BackColor); //Color clr = BackColor; switch (mouseAction) { case MouseActionType.Click: shadowOffset = 4; //clr = Color.Gold; btnOffset = 2; break; case MouseActionType.Hover: //clr = Color.Gold; break; } g.SmoothingMode = SmoothingMode.HighQuality; /// /// Create main colored shape /// Rectangle rc = new Rectangle(btnOffset, btnOffset, this.ClientSize.Width - 8 - btnOffset, this.ClientSize.Height - 8 - btnOffset); GraphicsPath path1 = this.GetPath(rc, 20); LinearGradientBrush br1 = new LinearGradientBrush(new Point(0, 0), new Point(0, rc.Height + 6), color1, color2); /// /// Create shadow /// if (addShadow == true) { Rectangle rc2 = rc; rc2.Offset(shadowOffset, shadowOffset); GraphicsPath path2 = this.GetPath(rc2, 20); PathGradientBrush br2 = new PathGradientBrush(path2); br2.CenterColor = ControlPaint.DarkDark(Color.Silver); br2.SurroundColors = new Color[] { Color.Transparent }; g.FillPath(br2, path2); //draw shadow /// ///Set the region for the button Region rgn = new Region(path1); rgn.Union(path2); this.Region = rgn; } /// /// Create top water color to give "aqua" effect /// Rectangle rc3 = rc; rc3.Inflate(-5, -5); rc3.Height = 15; GraphicsPath path3 = GetPath(rc3, 20); LinearGradientBrush br3 = new LinearGradientBrush(rc3, Color.FromArgb(255, gradientColor), Color.FromArgb(0, gradientColor), gradientMode); /// ///draw shapes /// g.FillPath(br1, path1); //draw main g.FillPath(br3, path3); //draw top bubble /// ///Create a backup of the button image to a bitmap so we can manipulate it's pulsing action /// buttonBitmapRectangle = new Rectangle(rc.Location, rc.Size); buttonBitmap = new Bitmap(buttonBitmapRectangle.Width, buttonBitmapRectangle.Height); Graphics g_bmp = Graphics.FromImage(buttonBitmap); g_bmp.SmoothingMode = SmoothingMode.HighQuality; g_bmp.FillPath(br1, path1); g_bmp.FillPath(br3, path3); /// /// Create a Path to draw the text to give the button a nice outline /// GraphicsPath path4 = new GraphicsPath(); RectangleF path1bounds = path1.GetBounds(); Rectangle rcText = new Rectangle((int)path1bounds.X, (int)path1bounds.Y, (int)path1bounds.Width, (int)path1bounds.Height); StringFormat strformat = new StringFormat(); strformat.Alignment = StringAlignment.Center; strformat.LineAlignment = StringAlignment.Center; path4.AddString(this.Text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size, rcText, strformat); Pen txtPen = new Pen(this.ForeColor, 1); g.DrawPath(txtPen, path4); g_bmp.DrawPath(txtPen, path4); }
// ==================================================================== // Creates the bitmap image. // ==================================================================== private void GenerateImage() { // Create a new 32-bit bitmap image. Bitmap bitmap = new Bitmap(this.width, this.height, PixelFormat.Format32bppArgb); // Create a graphics object for drawing. Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); // Fill in the background. HatchBrush hatchBrush = new HatchBrush(HatchStyle.OutlinedDiamond, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); // Set up the text font. SizeF size; float fontSize = rect.Height + 1; Font font; // Adjust the font size until the text fits within the image. do { fontSize--; font = new Font(this.familyName, fontSize, FontStyle.Strikeout); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(this.text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); // Draw the text. hatchBrush = new HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray); g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } // Clean up. font.Dispose(); hatchBrush.Dispose(); g.Dispose(); // Set the image. this.image = bitmap; }
static Bitmap DrawTop(string text) { using (var img = new Bitmap(ImageWidth, 150)) using (Graphics g = Graphics.FromImage(img)) { g.SmoothingMode = SmoothingMode.HighQuality; PrivateFontCollection coll = new PrivateFontCollection(); coll.AddFontFile(@"notobk-subset.otf"); FontFamily topFontFamily = coll.Families[0]; #region 5000兆円 の描画 // 黒色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(4, 4), null); var pen = new Pen(Brushes.Black, 22) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 銀色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(4, 4), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 20, ImageWidth, 135), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(0, 15, 36), Color.FromArgb(0, 15, 36), Color.FromArgb(255, 255, 255), Color.FromArgb(55, 58, 59), Color.FromArgb(55, 58, 59), Color.FromArgb(200, 200, 200), Color.FromArgb(55, 58, 59), Color.FromArgb(25, 20, 31), Color.FromArgb(240, 240, 240), Color.FromArgb(166, 175, 194), Color.FromArgb(50, 50, 50), Color.FromArgb(50, 50, 50), }, Positions = new[] { 0, 0.13f, 0.23f, 0.3f, 0.35f, 0.5f, 0.65f, 0.75f, 0.81f, 0.84f, 0.92f, 1, } }; brush.InterpolationColors = blend; var pen = new Pen(brush, 20) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 黒色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(0, 0), null); var pen = new Pen(Brushes.Black, 16) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 金色 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(0, 0), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 20, ImageWidth, 135), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(253, 241, 0), Color.FromArgb(253, 241, 0), Color.FromArgb(245, 253, 187), Color.FromArgb(255, 255, 255), Color.FromArgb(253, 219, 9), Color.FromArgb(127, 53, 0), Color.FromArgb(243, 196, 11), Color.FromArgb(243, 196, 11), }, Positions = new[] { 0, 0.12f, 0.25f, 0.35f, 0.56f, 0.66f, 0.73f, 1 } }; brush.InterpolationColors = blend; var pen = new Pen(brush, 10) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 黒 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(2, -3), null); var pen = new Pen(Brushes.Black, 6) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 白 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(0, -3), null); var pen = new Pen(Brushes.White, 6) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 赤 { var graphiscPath = new GraphicsPath(); graphiscPath.AddString(text, topFontFamily, 0, 100, new PointF(0, -3), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 20, ImageWidth, 122), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(255, 100, 0), Color.FromArgb(255, 100, 0), Color.FromArgb(123, 0, 0), Color.FromArgb(240, 0, 0), Color.FromArgb(5, 0, 0), Color.FromArgb(5, 0, 0), }, Positions = new[] { 0, 0.1f, 0.45f, 0.46f, 0.85f, 1 } }; brush.InterpolationColors = blend; var pen = new Pen(brush, 4) { LineJoin = LineJoin.Round, }; g.DrawPath(pen, graphiscPath); } // 赤 { GraphicsPath gPath = new GraphicsPath(); gPath.AddString(text, topFontFamily, 0, 100, new PointF(0, -3), null); LinearGradientBrush brush = new LinearGradientBrush(new RectangleF(0, 20, ImageWidth, 122), Color.AliceBlue, Color.AntiqueWhite, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend { Colors = new[] { Color.FromArgb(230, 0, 0), Color.FromArgb(230, 0, 0), Color.FromArgb(123, 0, 0), Color.FromArgb(240, 0, 0), Color.FromArgb(5, 0, 0), Color.FromArgb(5, 0, 0), }, Positions = new[] { 0, 0.1f, 0.45f, 0.46f, 0.85f, 1 } }; brush.InterpolationColors = blend; g.FillPath(brush, gPath); } #endregion var range = MeasureImage(img); return(img.Clone(new Rectangle(range.left, 0, range.right - range.left, img.Height), img.PixelFormat)); } }