コード例 #1
0
        private SimilarInfo GetrSimilarColorInfo(int percent)
        {
            SimilarInfo info = new SimilarInfo();

            if (percent < 0 || percent > 100)
            {
                return(info);
            }

            int   exactPixel = _position.X + (int)Math.Floor(_resBarLength * 1d * percent / 100d);
            Color col        = ColorUtils.GetColorAt(exactPixel + _offset.X, _position.Y + _offset.Y);
            int   diff       = ColorUtils.ColorDiff(col, _resBarColor);
            bool  isSimilar  = diff <= ColorDiffTolerance;

            info.Difference       = diff;
            info.Color            = col;
            info.IsSimilarWithBar = isSimilar;
            return(info);
        }
コード例 #2
0
        private int GetPercent()
        {
            int min = 0;
            int max = 100;

            //Binary search
            while (Math.Abs(max - min) > 1)
            {
                int         percent = (int)Math.Floor((min + max) / 2d);
                SimilarInfo simInfo = GetrSimilarColorInfo(percent);
                if (simInfo.IsSimilarWithBar)
                {
                    min = percent;
                }
                else
                {
                    max = percent;
                }
            }

            var maxInfo = GetrSimilarColorInfo(max);

            return((int)(maxInfo.IsSimilarWithBar ? max : min));
        }