Skip to content

Commit

Permalink
- Says the selected and picked color name.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlapstaart committed Aug 16, 2022
1 parent 1ee614d commit 0d19a3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
20 changes: 19 additions & 1 deletion ImageProc.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace GameOCRTTS
Expand Down Expand Up @@ -123,5 +127,19 @@ internal static Image Rescale(Image image, int dpiX, int dpiY)

return bm;
}

internal static string ColorToText(Color color)
{
int R = color.R;
int G = color.G;
int B = color.B;

var colorprops = typeof(Color).GetProperties(BindingFlags.Public | BindingFlags.Static);
var colors = new List<Color>();
colors.AddRange(colorprops.Select(x => (Color)x.GetValue(null, null)).Where(x => x.Name != Color.Transparent.Name).ToList());
Color nearest = colors.OrderBy(x => Math.Abs(x.R - R) + Math.Abs(x.G - G) + Math.Abs(x.B - B)).First();

return nearest.Name;
}
}
}
13 changes: 9 additions & 4 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ private void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
if (e.Modifier == SpecialKeys.Control)
{
Color color = ImageProc.GetColorFromCurrentPixel();
_OCR.Brightest = color;
colorPanel.BackColor = color;
SFXPlayer.PlayOK();
SetTextColor(color);
return;
}
else
Expand Down Expand Up @@ -139,8 +137,15 @@ private void selectColorButton_Click(object sender, EventArgs e)
if (colorSelect.ShowDialog() != DialogResult.OK)
return;

_OCR.Brightest = colorSelect.Color;
SetTextColor(colorSelect.Color);
}

private void SetTextColor(Color color)
{
_OCR.Brightest = color;
colorPanel.BackColor = _OCR.Brightest;
string colorname = ImageProc.ColorToText(color);
TTS.SpeakOut(colorname);
}

private void distanceBar_Scroll(object sender, EventArgs e)
Expand Down

0 comments on commit 0d19a3f

Please sign in to comment.