private void SetPickedColor(Color pColor) { Bitmap cView = new Bitmap(colorBox.Width, colorBox.Height); using (Graphics g = Graphics.FromImage(cView)) { g.Clear(pColor); using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(pColor))) { using (Pen p = new Pen(sb, 1)) { g.DrawRectangle(p, new Rectangle(1, 1, cView.Width - 3, cView.Height - 3)); } } } HSLColor hlc = HSLColor.FromColor(pColor); HSVColor hvc = HSVColor.FromColor(pColor); RGBColor rgc = RGBColor.FromColor(pColor); HEXColor hxc = HEXColor.FromColor(pColor); lbl_HTML.Text = hxc.ToString(); lbl_RGB.Text = rgc.ToString(); lbl_HSL.Text = hlc.ToString(); lbl_HSV.Text = hvc.ToString(); colorBox.Image?.Dispose(); colorBox.Image = cView; }
public static Color GetRandomColor(Color c1, Color c2, float?alpha = null) { // This isn't perfect because it will tend towards the middle of the colour // wheel, need to make hues wrap var c1Hsv = HSVColor.FromColor(c1); var c2Hsv = HSVColor.FromColor(c2); float hue = WrapFloat(c1Hsv.H, c2Hsv.H); if (alpha.HasValue) { return(Random.ColorHSV( hue, hue, Mathf.Min(c1Hsv.S, c2Hsv.S), Mathf.Max(c1Hsv.S, c2Hsv.S), Mathf.Min(c1Hsv.V, c2Hsv.V), Mathf.Max(c1Hsv.V, c2Hsv.V), alpha.Value, alpha.Value)); } return(Random.ColorHSV( hue, hue, Mathf.Min(c1Hsv.S, c2Hsv.S), Mathf.Max(c1Hsv.S, c2Hsv.S), Mathf.Min(c1Hsv.V, c2Hsv.V), Mathf.Max(c1Hsv.V, c2Hsv.V), Mathf.Min(c1.a, c2.a), Mathf.Max(c1.a, c2.a) )); }
public HSVColorBuffer(int width, int height, Color[] colorData) { this.width = width; this.height = height; this.data = new HSVColor[colorData.Length]; for (int i = 0; i < colorData.Length; i++) { this.data[i] = HSVColor.FromColor(colorData[i]); } }
public static Color GetRandomColor(Color c1, Color c2, float alpha, float saturation) { var c1Hsv = HSVColor.FromColor(c1); var c2Hsv = HSVColor.FromColor(c2); float hue = WrapFloat(c1Hsv.H, c2Hsv.H); return(Random.ColorHSV( hue, hue, saturation, saturation, Mathf.Min(c1Hsv.V, c2Hsv.V), Mathf.Max(c1Hsv.V, c2Hsv.V), alpha, alpha)); }
IEnumerator FloodFill(Vector2 startPos, Color maskColor, float hueTolerance, float saturationTolerance, float valueTolerance, ColorBuffer32 pixelBuffer, ColorBuffer32 masksBuffer) { startTime = Time.time; DecoratorPanel.Instance.progressIndicator.SetActive(true); yield return(new WaitForEndOfFrame()); yield return(null); Color32 startColor = pixelBuffer[(int)startPos.x, (int)startPos.y]; Debug.Log(HSVColor.FromColor(startColor).ToString()); Point start = new Point((int)startPos.x, (int)startPos.y, startColor); ColorBuffer32 copyBmp = new ColorBuffer32(pixelBuffer.width, pixelBuffer.height, (Color32[])pixelBuffer.data.Clone()); copyBmp[start.x, start.y] = maskColor; Queue <Point> openNodes = new Queue <Point>(); openNodes.Enqueue(start); int i = 0; int emergency = pixelBuffer.width * pixelBuffer.height; while (openNodes.Count > 0) { i++; if (i > emergency) { yield break; } Point current = openNodes.Dequeue(); int x = current.x; int y = current.y; Color32 currentColor = current.color; if (x > 0 && copyBmp[x - 1, y] != Color.black && masksBuffer[x - 1, y] != maskColor) { ProcessPixel(x - 1, y, ref currentColor, startColor, maskColor, hueTolerance, saturationTolerance, valueTolerance, openNodes, pixelBuffer, masksBuffer, copyBmp); } if (x < pixelBuffer.width - 1 && copyBmp[x + 1, y] != Color.black && masksBuffer[x + 1, y] != maskColor) { ProcessPixel(x + 1, y, ref currentColor, startColor, maskColor, hueTolerance, saturationTolerance, valueTolerance, openNodes, pixelBuffer, masksBuffer, copyBmp); } if (y > 0 && copyBmp[x, y - 1] != Color.black && masksBuffer[x, y - 1] != maskColor) { ProcessPixel(x, y - 1, ref currentColor, startColor, maskColor, hueTolerance, saturationTolerance, valueTolerance, openNodes, pixelBuffer, masksBuffer, copyBmp); } if (y < pixelBuffer.height - 1 && copyBmp[x, y + 1] != Color.black && masksBuffer[x, y + 1] != maskColor) { ProcessPixel(x, y + 1, ref currentColor, startColor, maskColor, hueTolerance, saturationTolerance, valueTolerance, openNodes, pixelBuffer, masksBuffer, copyBmp); } } UpdateMaskPixels(); DecoratorPanel.Instance.progressIndicator.SetActive(false); Debug.Log(Time.time - startTime); }
private void lbl_HSV_MouseDoubleClick(object sender, MouseEventArgs e) { Copy(HSVColor.FromColor(ldcPlate.SelectedColor)); }
// 임시 핫키 세팅과 연동 필요함 private void InitHotKey() { Keys[] semi_hkKeys = new Keys[] { Keys.Left, Keys.Right, Keys.Up, Keys.Down }; Point[] semi_hkDeltas = new Point[] { new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1) }; for (int i = 0; i < semi_hkDeltas.Length; i++) { int idx = i; HotkeyManager.Register($"SEMI_{semi_hkKeys[idx].ToString()}", new HotKey() { Keys = new Keys[] { semi_hkKeys[idx] }, Action = () => { if (setting.SemiControl) { Point acPt = Point.Empty; if (HotkeyManager.IsShift()) { acPt = new Point(semi_hkDeltas[idx].X * 3, semi_hkDeltas[idx].Y * 3); } SetCursorPosDelta(semi_hkDeltas[idx] + (Size)acPt); } } }); } HotkeyManager.Register("Pause", new HotKey() { Keys = new Keys[] { Keys.None, Keys.F1 }, Action = () => { mPause = !mPause; } }); HotkeyManager.Register("ZoomIn", new HotKey() { Keys = new Keys[] { Keys.None, Keys.Add }, Action = () => { zoomSlider.Value += 1; } }); HotkeyManager.Register("ZoomOut", new HotKey() { Keys = new Keys[] { Keys.None, Keys.Subtract }, Action = () => { zoomSlider.Value -= 1; } }); HotkeyManager.Register("RGB", new HotKey() { Keys = new Keys[] { Keys.None, Keys.F2 }, Action = () => { AddColor(RGBColor.FromColor(ldcPlate.SelectedColor)); } }); HotkeyManager.Register("HEX", new HotKey() { Keys = new Keys[] { Keys.None, Keys.F3 }, Action = () => { AddColor(HEXColor.FromColor(ldcPlate.SelectedColor)); } }); HotkeyManager.Register("HSL", new HotKey() { Keys = new Keys[] { Keys.None, Keys.F4 }, Action = () => { AddColor(HSLColor.FromColor(ldcPlate.SelectedColor)); } }); HotkeyManager.Register("HSB", new HotKey() { Keys = new Keys[] { Keys.None, Keys.F5 }, Action = () => { AddColor(HSVColor.FromColor(ldcPlate.SelectedColor)); } }); }