Returns true if the given pixel is empty (i.e. black) - CSharp System.Drawing.Imaging

CSharp examples for System.Drawing.Imaging:BitmapData

Description

Returns true if the given pixel is empty (i.e. black)

Demo Code


using System.Drawing.Imaging;

public class Main{
        /// <summary>
        /// Returns true if the given pixel is empty (i.e. black)
        /// </summary>
        /// <param name="bitmapData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private static unsafe bool IsEmptyPixel(BitmapData bitmapData, int x, int y)
        {//from   w  w w  .j  ava 2  s  .com
            var addr = (byte*)(bitmapData.Scan0) + bitmapData.Stride * y + x * 3;
            return (*addr == 0 && *(addr + 1) == 0 && *(addr + 2) == 0);
        }
}

Related Tutorials