Ejemplo n.º 1
0
        private void CreateTransformedImage()
        {
            Bitmap bitmap;

            ArgbColor[]     originalData;
            Size            size;
            IErrorDiffusion dither;

            this.CleanUpTransformed();

            if (_image == null)
            {
                return;
            }

            bitmap = _image;
            size   = bitmap.Size;

            int levels = (int)GrayscaleLevel.Value;
            int matrix = (int)ditherMatrix.Value;

            originalData = bitmap.GetPixelsFrom32BitArgbImage();

            dither = errorDiffusion.GetDitheringInstance();

            for (int row = 0; row < size.Height; row++)
            {
                for (int col = 0; col < size.Width; col++)
                {
                    int       index;
                    ArgbColor current;
                    ArgbColor transformed;

                    index = row * size.Width + col;

                    current = originalData[index];

                    // transform the pixel - normally this would be some form of color
                    // reduction. For this sample it's simple threshold based
                    // monochrome conversion
                    transformed         = PixelUtilities.TransformPixel(current, form1);
                    originalData[index] = transformed;

                    // apply a dither algorithm to this pixel
                    if (dither != null)
                    {
                        dither.Diffuse(originalData, current, transformed, col, row, size.Width, size.Height, levels, matrix);
                    }
                }
            }

            _transformed        = originalData.ToBitmap(size);
            WorkedPicture.Image = _transformed;
        }