/// <summary> /// Default constructor /// </summary> /// <param name="bmp">The bitmap</param> public BitmapLock(Bitmap bmp) { // Get the bitmap SourceBmp = bmp; // Get width and height of bitmap Width = SourceBmp.Width; Height = SourceBmp.Height; // Create rectangle to lock Rectangle rect = new Rectangle(0, 0, Width, Height); // Make sure the pixel format is supported if (!SupportedPixelFormats.Contains(PixelFormat)) { throw new ArgumentException($"The pixel format {PixelFormat} of the bitmap is not supported"); } // Lock bitmap and return bitmap data BitmapData = SourceBmp.LockBits(rect, ImageLockMode.ReadWrite, SourceBmp.PixelFormat); // Create byte array to copy pixel values Pixels = new byte[Width * Height * (Image.GetPixelFormatSize(PixelFormat) / 8)]; // Get the pointer address Iptr = BitmapData.Scan0; // Copy data from pointer to array Marshal.Copy(Iptr, Pixels, 0, Pixels.Length); }
public static VideoFormat GetVideoFormat(_BMDPixelFormat pixFormat) { VideoFormat format = null; if (SupportedPixelFormats.ContainsKey(pixFormat)) { format = SupportedPixelFormats[pixFormat]; } return(format); }