Пример #1
0
        public static string ToSql(this Enum value)
        {
            if (value == null)
            {
                return("Null");
            }

            TypeCode typeCode = value.GetTypeCode();

            ConvertionMethod convertion = (ConvertionMethod)EnumExtensions.Convertions[typeCode] ?? (ConvertionMethod)(args => { throw new NotImplementedException(); });

            string result = convertion(value);

            return(result);
        }
Пример #2
0
        public static byte[] FromBitmap(Bitmap bmp, ConvertionMethod method, DitheringMethod dither, bool serpentine, int grayScaleDepth)
        {
            if (!(new[] { 2, 4, 8, 16, 32, 64, 128, 256 }).Contains(grayScaleDepth))
            {
                throw new Exception("GrayScaleDepth must be a power of 2 between 1 and 254");
            }

            byte[] output = new byte[0];

            output = ConvertToGrayscale(bmp, method, grayScaleDepth);

            output = Dither(output, grayScaleDepth, bmp.Width, bmp.Height, dither, serpentine);

            return(output);
        }
Пример #3
0
        public static byte[] ConvertToGrayscale(Bitmap bmp, ConvertionMethod method, int grayScaleDepth)
        {
            byte[] output = new byte[0];

            switch (method)
            {
            case ConvertionMethod.Average:
                output = ConvAverage(bmp, grayScaleDepth, 1 / 3.0, 1 / 3.0, 1 / 3.0);
                break;

            case ConvertionMethod.AverageBT709:
                output = ConvAverage(bmp, grayScaleDepth, 0.2126, 0.7152, 0.0722);
                break;

            case ConvertionMethod.AverageBT601:
                output = ConvAverage(bmp, grayScaleDepth, 0.299, 0.587, 0.114);
                break;

            case ConvertionMethod.Desaturation:
                output = ConvDesaturation(bmp, grayScaleDepth);
                break;

            case ConvertionMethod.DecompositionMax:
                output = ConvDecompositionMax(bmp, grayScaleDepth);
                break;

            case ConvertionMethod.DecompositionMin:
                output = ConvDecompositionMin(bmp, grayScaleDepth);
                break;

            case ConvertionMethod.SingleChannelRed:
                output = ConvSingleChannel(bmp, grayScaleDepth, Color.Red);
                break;

            case ConvertionMethod.SingleChannelGreen:
                output = ConvSingleChannel(bmp, grayScaleDepth, Color.Green);
                break;

            case ConvertionMethod.SingleChannelBlue:
                output = ConvSingleChannel(bmp, grayScaleDepth, Color.Blue);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(method), method, null);
            }
            return(output);
        }