AForge.Imaging.Image.CreateGrayscaleImage C# (CSharp) Method

CreateGrayscaleImage() public static method

Create and initialize new 8 bpp grayscale image.
The method creates new 8 bpp grayscale image and initializes its palette. Grayscale image is represented as Format8bppIndexed image with palette initialized to 256 gradients of gray color.
public static CreateGrayscaleImage ( int width, int height ) : Bitmap
width int Image width.
height int Image height.
return System.Drawing.Bitmap
        public static Bitmap CreateGrayscaleImage( int width, int height )
        {
            // create new image
            Bitmap image = new Bitmap( width, height, PixelFormat.Format8bppIndexed );
            // set palette to grayscale
            SetGrayscalePalette( image );
            // return new image
            return image;
        }

Usage Example

Beispiel #1
0
        public unsafe Bitmap ToBitmap()
        {
            if (houghMap == null)
            {
                throw new ApplicationException("Hough transformation was not done yet.");
            }
            int        length     = houghMap.GetLength(1);
            int        length2    = houghMap.GetLength(0);
            Bitmap     bitmap     = Image.CreateGrayscaleImage(length, length2);
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, length, length2), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            int        num        = bitmapData.Stride - length;
            float      num2       = 255f / (float)maxMapIntensity;
            byte *     ptr        = (byte *)bitmapData.Scan0.ToPointer();

            for (int i = 0; i < length2; i++)
            {
                int num3 = 0;
                while (num3 < length)
                {
                    *ptr = (byte)System.Math.Min(255, (int)(num2 * (float)houghMap[i, num3]));
                    num3++;
                    ptr++;
                }
                ptr += num;
            }
            bitmap.UnlockBits(bitmapData);
            return(bitmap);
        }
All Usage Examples Of AForge.Imaging.Image::CreateGrayscaleImage