FRBDK/FilteringHaloRemover/FilteringHaloRemover/FormMain.cs
/// <summary>
/// Returns the color the supplied pixel should be by averaging the surrounding pixel color values of non transparent pixels.
/// </summary>
/// <param name="bitmap"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
Returns the color the supplied pixel should be by averaging the surrounding pixel color values of non transparent pixels.
Returns the color the supplied pixel should be by averaging the surrounding pixel color values of non transparent pixels .
private Color DeterminePixelColorAverage(int x, int y, Color originalColor)
        {
            int R = 0;
            int G = 0;
            int B = 0;
            int count = 0;
            List<Color> colorList = new List<Color>();
            bool canProcessRight = (x < (colorArray.GetLength(0) - 1));
            bool canProcessLeft = (x > 0);
            if (canProcessLeft)
            {
                colorList.Add(colorArray[(x - 1), y]);
                try { colorList.Add(colorArray[(x - 1), (y - 1)]); }
                catch { }
                try { colorList.Add(colorArray[(x - 1), (y + 1)]); }
                catch { }
            }
            if (canProcessRight)
            {
                colorList.Add(colorArray[(x + 1), y]);
                try { colorList.Add(colorArray[(x + 1), (y - 1)]); }
                catch { }
                try { colorList.Add(colorArray[(x + 1), (y + 1)]); }
                catch { }
            }
            try { colorList.Add(colorArray[x, (y + 1)]); }
            catch { }
            try { colorList.Add(colorArray[x, (y - 1)]); }
            catch { }
            foreach (Color tmpC in colorList)
            {
                if (tmpC.A > 0)
                {
                    count++;
                    R += tmpC.R;
                    G += tmpC.G;
                    B += tmpC.B;
                }
            }
            if (count > 0)
            {
                return Color.FromArgb(0, R / count, G / count, B / count);
            }
            else
            {
                return originalColor;
            }
        }
private Color DeterminePixelColorAverage ( int x , int y , Color originalColor ) { int R = 0 ; int G = 0 ; int B = 0 ; int count = 0 ; List < Color > colorList = new List < Color > ( ) ; bool canProcessRight = ( x < ( colorArray . GetLength ( 0 ) - 1 ) ) ; bool canProcessLeft = ( x > 0 ) ; if ( canProcessLeft ) { colorList . Add ( colorArray [ ( x - 1 ) , y ] ) ; try { colorList . Add ( colorArray [ ( x - 1 ) , ( y - 1 ) ] ) ; } catch { } try { colorList . Add ( colorArray [ ( x - 1 ) , ( y + 1 ) ] ) ; } catch { } } if ( canProcessRight ) { colorList . Add ( colorArray [ ( x + 1 ) , y ] ) ; try { colorList . Add ( colorArray [ ( x + 1 ) , ( y - 1 ) ] ) ; } catch { } try { colorList . Add ( colorArray [ ( x + 1 ) , ( y + 1 ) ] ) ; } catch { } } try { colorList . Add ( colorArray [ x , ( y + 1 ) ] ) ; } catch { } try { colorList . Add ( colorArray [ x , ( y - 1 ) ] ) ; } catch { } foreach ( Color tmpC in colorList ) { if ( tmpC . A > 0 ) { count ++ ; R += tmpC . R ; G += tmpC . G ; B += tmpC . B ; } } if ( count > 0 ) { return Color . FromArgb ( 0 , R / count , G / count , B / count ) ; } else { return originalColor ; } }
Returns the color the supplied pixel should be by averaging the surrounding pixel color values of non transparent pixels.
Returns the color the supplied pixel should be by averaging the surrounding pixel color values of non transparent pixels .
//@kao TODO //only return if one or more of the surrounding pixels were non-transparent. //return Color.FromArgb(255, R / count, G / count, B / count); //return Color.Black;
None
x
int
None
y
int
None
originalColor
Color
bitmap
None