public static Bitmap2 GetImage(char c, int width, int height, Color2 fgColor, Color2 bgColor) { if (height <= 1 || width <= 1) { return null; } Bitmap2 template = GetImage(c); if (template == null) { return null; } int twidth = template.Width; int theight = template.Height; Bitmap2 result = new Bitmap2(width, height); for (int i = 0; i < width; i++) { float wI1; float wI2; int indI = CalcInd(i, width, twidth, out wI1, out wI2); for (int j = 0; j < height; j++) { float wJ1; float wJ2; int indJ = CalcInd(j, height, theight, out wJ1, out wJ2); Color2 ij = IsSet(indI, indJ, template) ? fgColor : bgColor; Color2 ipj = IsSet(indI + 1, indJ, template) ? fgColor : bgColor; Color2 ijp = IsSet(indI, indJ + 1, template) ? fgColor : bgColor; Color2 ipjp = IsSet(indI + 1, indJ + 1, template) ? fgColor : bgColor; Color2 col = Average(new[] { ij, ipj, ijp, ipjp }, new[] { wI1 * wJ1, wI2 * wJ1, wI1 * wJ2, wI2 * wJ2 }); result.SetPixel(i, j, col); } } return result; }
public static void PaintOverview(IGraphics g, SizeI2 totalSize, RectangleI2 visibleWin, Func <int, int, Bitmap2> getOverviewBitmap, float zoomFactorX, float zoomFactorY) { Size2 overview = CalcOverviewSize(visibleWin.Width, visibleWin.Height, totalSize.Width, totalSize.Height); Rectangle2 win = CalcWin(overview, totalSize, visibleWin, zoomFactorX, zoomFactorY); g.FillRectangle(Brushes2.White, 0, visibleWin.Height - overview.Height, overview.Width, overview.Height); g.DrawImageUnscaled(getOverviewBitmap((int)overview.Width, (int)overview.Height), 0, visibleWin.Height - overview.Height); Brush2 b = new Brush2(Color2.FromArgb(30, 0, 0, 255)); if (win.X > 0) { g.FillRectangle(b, 0, visibleWin.Height - overview.Height, win.X, overview.Height); } if (overview.Width - win.X - win.Width > 0) { g.FillRectangle(b, win.X + win.Width, visibleWin.Height - overview.Height, overview.Width - win.X - win.Width, overview.Height); } if (win.Y > 0) { g.FillRectangle(b, win.X, visibleWin.Height - overview.Height, win.Width, win.Y); } if (overview.Height - win.Y - win.Height > 0) { g.FillRectangle(b, win.X, visibleWin.Height - overview.Height + win.Y + win.Height - 1, win.Width, overview.Height - win.Y - win.Height); } g.DrawRectangle(Pens2.Black, 0, visibleWin.Height - overview.Height - 1, overview.Width, overview.Height); g.DrawRectangle(Pens2.Blue, win.X, visibleWin.Height - overview.Height - 1 + win.Y, win.Width, win.Height); }
public static Color2 Darker(Color2 baseColor, int n) { return (new Color2( (int) MakeArgb(CheckByte(baseColor.A), CheckByte(Math.Max(0, baseColor.R - n)), CheckByte(Math.Max(0, baseColor.G - n)), CheckByte(Math.Max(0, baseColor.B - n))), stateArgbValueValid, 0)); }
public static Color2 Lighter(Color2 baseColor, int n) { return (new Color2( (int) MakeArgb(CheckByte(baseColor.A), CheckByte(Math.Min(255, baseColor.R + n)), CheckByte(Math.Min(255, baseColor.G + n)), CheckByte(Math.Min(255, baseColor.B + n))), stateArgbValueValid, 0)); }
public PlanePropertiesForm(Color2 horizontalGridColor, Color2 verticalGridColor, GridType horizontalGrid, GridType verticalGrid, int horizontalGridWidth, int verticalGridWidth, Color2 borderColor, Color2 backgroundColor, Color2 axisColor, int majorTickLength, float majorTickLineWidth, int minorTickLength, float minorTickLineWidth, bool topAxisVisible, bool rightAxisVisible, float axisLineWidth, int numbersFontSize, bool numbersFontBold, int titleFontSize, bool titleFontBold, Color2 horizontalZeroColor, Color2 verticalZeroColor, int horizontalZeroWidth, int verticalZeroWidth, bool horizontalZeroVisible, bool verticalZeroVisible) { InitializeComponent(); numbersFontSizeNumericUpDown.Value = numbersFontSize; numbersFontBoldCheckBox.Checked = numbersFontBold; titlesFontSizeNumericUpDown.Value = titleFontSize; titlesFontBoldCheckBox.Checked = titleFontBold; horizontalGridColorButton.BackColor = GraphUtils.ToColor(horizontalGridColor); verticalGridColorButton.BackColor = GraphUtils.ToColor(verticalGridColor); lineWidthNumericUpDown.Value = (decimal) axisLineWidth; switch (horizontalGrid){ case GridType.None: horizontalGridComboBox.SelectedIndex = 0; break; case GridType.Major: horizontalGridComboBox.SelectedIndex = 1; break; case GridType.All: horizontalGridComboBox.SelectedIndex = 2; break; } switch (verticalGrid){ case GridType.None: verticalGridComboBox.SelectedIndex = 0; break; case GridType.Major: verticalGridComboBox.SelectedIndex = 1; break; case GridType.All: verticalGridComboBox.SelectedIndex = 2; break; } showTopAxisCheckBox.Checked = topAxisVisible; showRightAxisCheckBox.Checked = rightAxisVisible; horizontalGridNumericUpDown.Value = horizontalGridWidth; verticalGridNumericUpDown.Value = verticalGridWidth; fillColorButton.BackColor = GraphUtils.ToColor(borderColor); backgroundColorButton.BackColor = GraphUtils.ToColor(backgroundColor); lineColorButton.BackColor = GraphUtils.ToColor(axisColor); majorTicLengthNumericUpDown.Value = majorTickLength; minorTicLengthNumericUpDown.Value = minorTickLength; majorTicLineWidthNumericUpDown.Value = (decimal) majorTickLineWidth; minorTicLineWidthNumericUpDown.Value = (decimal) minorTickLineWidth; horizontalZeroColorButton.BackColor = GraphUtils.ToColor(horizontalZeroColor); verticalZeroColorButton.BackColor = GraphUtils.ToColor(verticalZeroColor); horizontalZeroNumericUpDown.Value = horizontalZeroWidth; verticalZeroNumericUpDown.Value = verticalZeroWidth; horizontalZeroCheckBox.Checked = horizontalZeroVisible; verticalZeroCheckBox.Checked = verticalZeroVisible; }
public override bool Equals(object obj) { if (obj is Color2) { Color2 right = (Color2)obj; if (value == right.value && state == right.state && knownColor == right.knownColor) { return(true); } } return(false); }
/// <summary> /// Initializes a new instance of the <code>Bitmap2</code> class from the specified data stream. /// </summary> /// <param name="stream">The data stream used to load the image.</param> public Bitmap2(Stream stream) { if (stream == null) { throw new ArgumentNullException(); } Image2 im = new Image2(stream); data = new int[im.Height, im.Width]; for (int i = 0; i < im.Pixels.Length; i++) { Color2 c = im.Pixels[i]; SetPixel(i % im.Width, i / im.Width, Color2.FromArgb(c.A, c.R, c.G, c.B)); } }
public ColorStripView(Color2 c1, Color2 c2) { Positions = new List<double>(); Colors = new List<Color2>(); if (Colors.Count == 0){ AddColor(c1, 0); AddColor(c2, 1.0); } Arrow = Arrows.Second; StripWidth = 10; Vertical = false; Weight1 = 1F; Weight2 = 0F; InitColors(Colors.ToArray(), Positions.ToArray()); }
public Bitmap2 Lighter() { Bitmap2 result = new Bitmap2(Width, Height); for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { int p = GetPixel(i, j); result.SetPixel(i, j, Color2.FromArgb(Math.Min(255, Color2.GetR(p) + 20), Math.Min(255, Color2.GetG(p) + 20), Math.Min(255, Color2.GetB(p) + 20)).Value); } } return(result); }
public static void PaintOverview(IGraphics g, SizeI2 totalSize, RectangleI2 visibleWin, Func <int, int, Bitmap2> getOverviewBitmap, float zoomFactorX, float zoomFactorY, bool overviewTopRight) { if (getOverviewBitmap == null) { return; } Size2 overview = CalcOverviewSize(visibleWin.Width, visibleWin.Height, totalSize.Width, totalSize.Height); Rectangle2 win = CalcWin(overview, totalSize, visibleWin, zoomFactorX, zoomFactorY); float xpos = overviewTopRight ? visibleWin.Width - overview.Width - 1 : 0; float ypos = overviewTopRight ? 1 : visibleWin.Height - overview.Height; g.FillRectangle(Brushes2.White, xpos, ypos, overview.Width, overview.Height); Bitmap2 bm = getOverviewBitmap((int)overview.Width, (int)overview.Height); if (bm == null) { return; } g.DrawImageUnscaled(bm, xpos, ypos); Brush2 b = new Brush2(Color2.FromArgb(30, 0, 0, 255)); if (win.X > 0) { g.FillRectangle(b, xpos, ypos, win.X, overview.Height); } if (overview.Width - win.X - win.Width > 0) { g.FillRectangle(b, xpos + win.X + win.Width, ypos, overview.Width - win.X - win.Width, overview.Height); } if (win.Y > 0) { g.FillRectangle(b, xpos + win.X, ypos, win.Width, win.Y); } if (overview.Height - win.Y - win.Height > 0) { g.FillRectangle(b, xpos + win.X, ypos + win.Y + win.Height - 1, win.Width, overview.Height - win.Y - win.Height); } g.DrawRectangle(Pens2.Black, xpos, ypos - 1, overview.Width, overview.Height); g.DrawRectangle(Pens2.Blue, xpos + win.X, ypos - 1 + win.Y, win.Width, win.Height); if (win.Width < 5 && win.Height < 5) { g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X + 5, ypos + win.Y); g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X, ypos + win.Y + 5); g.DrawLine(Pens2.Red, xpos + win.X, ypos + win.Y, xpos + win.X + 7, ypos + win.Y + 7); } }
private static Color2 Average(IList <Color2> colors, IList <float> weights) { float r = 0; float g = 0; float b = 0; float norm = 0; for (int i = 0; i < colors.Count; i++) { Color2 col = colors[i]; float w = weights[i]; r += col.R * w; g += col.G * w; b += col.B * w; norm += w; } Color2 x = Color2.FromArgb(255, (int)Math.Round(r / norm), (int)Math.Round(g / norm), (int)Math.Round(b / norm)); return(x); }
public static Bitmap2 GetImage(char c, int width, int height, Color2 fgColor, Color2 bgColor) { if (height <= 1 || width <= 1) { return(null); } Bitmap2 template = GetImage(c); if (template == null) { return(null); } int twidth = template.Width; int theight = template.Height; Bitmap2 result = new Bitmap2(width, height); for (int i = 0; i < width; i++) { float wI1; float wI2; int indI = CalcInd(i, width, twidth, out wI1, out wI2); for (int j = 0; j < height; j++) { float wJ1; float wJ2; int indJ = CalcInd(j, height, theight, out wJ1, out wJ2); Color2 ij = IsSet(indI, indJ, template) ? fgColor : bgColor; Color2 ipj = IsSet(indI + 1, indJ, template) ? fgColor : bgColor; Color2 ijp = IsSet(indI, indJ + 1, template) ? fgColor : bgColor; Color2 ipjp = IsSet(indI + 1, indJ + 1, template) ? fgColor : bgColor; Color2 col = Average(new[] { ij, ipj, ijp, ipjp }, new[] { wI1 *wJ1, wI2 *wJ1, wI1 *wJ2, wI2 *wJ2 }); result.SetPixel(i, j, col); } } return(result); }
public static Color2 Lighter(Color2 baseColor, int n) { return new Color2( (int) MakeArgb(CheckByte(baseColor.A), CheckByte(Math.Min(255, baseColor.R + n)), CheckByte(Math.Min(255, baseColor.G + n)), CheckByte(Math.Min(255, baseColor.B + n))), stateArgbValueValid, 0); }
public string GetColor(Color2 color) { //if (color.IsNamedColor) //{ // return color.Name; //} return $"rgb({color.R},{color.G},{color.B})"; }
public void DrawPath(Color2 c, int x, int y, int[] xpath, int[] ypath) { DrawPath(c.Value, x, y, xpath, ypath); }
public void DrawRectangle(Color2 c, int x, int y, int wid, int height) { DrawRectangle(c.Value, x, y, wid, height); }
/// <summary> /// Creates a new <code>Color2</code> from the specified <code>Color2</code>, but with /// the new specified alpha value. /// </summary> public static Color2 FromArgb(int alpha, Color2 baseColor) { return(new Color2((int)MakeArgb(CheckByte(alpha), baseColor.R, baseColor.G, baseColor.B), stateArgbValueValid, 0)); }
public void InitColors(Color2[] colors, double[] positions) { ColorStrip.InitColors(colors, positions); }
public static Color ToColor(Color2 c) { return Color.FromArgb(c.A, c.R, c.G, c.B); }
public void SetPixel(int i, int j, Color2 c) { SetPixel(i, j, c.Value); }
public void FillRectangle(Color2 c, int x, int y, int wid, int height) { FillRectangle(c.Value, x, y, wid, height); }
private static bool IsSet(int i, int j, Bitmap2 b) { return(Color2.GetR(b.GetPixel(i, j)) == 0); }
private void CalcGradient(Color2 c1, Color2 c2, int a1, int a2) { for (int j = a1 + 1; j <= a2; j++){ double w1 = Math.Abs(a2 - j); double w2 = Math.Abs(j - a1); byte rr = (byte) Math.Round((c1.R*w1 + c2.R*w2)/(w1 + w2)); byte gg = (byte) Math.Round((c1.G*w1 + c2.G*w2)/(w1 + w2)); byte bb = (byte) Math.Round((c1.B*w1 + c2.B*w2)/(w1 + w2)); precalcColors[j] = Color2.FromArgb(rr, gg, bb); precalcPens[j] = new Pen2(precalcColors[j]); } }
public void DrawLine(Color2 c, int x1, int y1, int x2, int y2, bool dots, int width1) { DrawLine(c.Value, x1, y1, x2, y2, dots, width1); }
public Pen2(Color2 color, float width) { Color = color; Width = width; DashCap = DashCap2.Flat; }
internal void AddColor(Color2 color, double position) { Colors.Add(color); Positions.Add(position); }
public Pen2(Color2 color) : this(color, 1f) { }
public static Color2 Darker(Color2 baseColor, int n) { return new Color2( (int) MakeArgb(CheckByte(baseColor.A), CheckByte(Math.Max(0, baseColor.R - n)), CheckByte(Math.Max(0, baseColor.G - n)), CheckByte(Math.Max(0, baseColor.B - n))), stateArgbValueValid, 0); }
/// <summary> /// Creates a new <code>Color2</code> from the specified <code>Color2</code>, but with /// the new specified alpha value. /// </summary> public static Color2 FromArgb(int alpha, Color2 baseColor) { return new Color2((int) MakeArgb(CheckByte(alpha), baseColor.R, baseColor.G, baseColor.B), stateArgbValueValid, 0); }
public void Clear(Color2 color) { template.SetRGBColorFill(color.R, color.G, color.B); template.Rectangle(0, 0, template.Width, template.Height); template.FillStroke(); }
public static void FillShadedRectangle(Bitmap2 b, int w, int h) { b.FillRectangle(Color2.White, 0, 0, w - 1, h - 1); b.SetPixel(1, 1, Color2.FromArgb(230, 238, 252)); b.SetPixel(1, h - 3, Color2.FromArgb(219, 227, 248)); b.SetPixel(w - 3, 1, Color2.FromArgb(220, 230, 249)); b.SetPixel(w - 3, h - 3, Color2.FromArgb(217, 227, 246)); b.SetPixel(w - 1, h - 3, Color2.FromArgb(174, 192, 214)); b.SetPixel(w - 2, h - 2, Color2.FromArgb(174, 196, 219)); b.SetPixel(0, h - 2, Color2.FromArgb(195, 212, 231)); b.SetPixel(0, h - 1, Color2.FromArgb(237, 241, 243)); b.SetPixel(w - 2, h - 1, Color2.FromArgb(236, 242, 247)); b.SetPixel(w - 1, h - 1, Color2.FromArgb(255, 255, 255)); b.SetPixel(w - 1, h - 2, Color2.FromArgb(255, 255, 255)); int wi = w - 5; int he = h - 5; int[][] upper = InterpolateRgb(225, 234, 254, 188, 206, 250, wi); int[][] lower = InterpolateRgb(183, 203, 249, 174, 200, 247, wi); for (int i = 0; i < wi; i++) { int[][] pix = InterpolateRgb(upper[0][i], upper[1][i], upper[2][i], lower[0][i], lower[1][i], lower[2][i], he); for (int j = 0; j < he; j++) { b.SetPixel(i + 2, j + 2, Color2.FromArgb(pix[0][j], pix[1][j], pix[2][j])); } } int[][] pix2 = InterpolateRgb(208, 223, 252, 170, 192, 243, he); for (int j = 0; j < he; j++) { b.SetPixel(1, j + 2, Color2.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j])); } pix2 = InterpolateRgb(185, 202, 243, 176, 197, 242, he); for (int j = 0; j < he; j++) { b.SetPixel(w - 3, j + 2, Color2.FromArgb(pix2[0][j], pix2[1][j], pix2[2][j])); } pix2 = InterpolateRgb(208, 223, 252, 175, 197, 244, wi); for (int i = 0; i < wi; i++) { b.SetPixel(i + 2, 1, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i])); } pix2 = InterpolateRgb(183, 198, 241, 176, 196, 242, wi); for (int i = 0; i < wi; i++) { b.SetPixel(i + 2, h - 3, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i])); } pix2 = InterpolateRgb(238, 237, 229, 160, 181, 211, he + 2); for (int i = 0; i < he + 2; i++) { b.SetPixel(w - 1, i, Color2.FromArgb(pix2[0][i], pix2[1][i], pix2[2][i])); } pix2 = InterpolateRgb(170, 192, 225, 126, 159, 211, w / 2); for (int i = 1; i <= w / 2; i++) { b.SetPixel(i, h - 1, Color2.FromArgb(pix2[0][i - 1], pix2[1][i - 1], pix2[2][i - 1])); } pix2 = InterpolateRgb(126, 159, 211, 148, 176, 221, w - 3 - w / 2); for (int i = w / 2 + 1; i <= w - 3; i++) { b.SetPixel(i, h - 1, Color2.FromArgb(pix2[0][i - w / 2 - 1], pix2[1][i - w / 2 - 1], pix2[2][i - w / 2 - 1])); } }
public void InitColors(Color2[] newColors, double[] newPositions) { Colors.Clear(); Colors.AddRange(newColors); Positions.Clear(); Positions.AddRange(newPositions); precalcColors = null; }