public static unsafe Bitmap ToBitmap( this IReadOnlyPixelBuffer pixels, Rectangle?sourceRectangle = null) { var srcRect = sourceRectangle ?? pixels.GetBounds(); ImagingArgumentGuard.AssertRectangleInSource(pixels, srcRect, nameof(sourceRectangle)); var srcType = pixels.PixelType; var dstType = VectorType.Get <Bgra32>(); var convertPixels = Imaging.Image.GetConvertPixelsDelegate(srcType, dstType); int width = srcRect.Width; int height = srcRect.Height; var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); var bmpRect = new System.Drawing.Rectangle(0, 0, width, height); var bmpData = bitmap.LockBits(bmpRect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); try { for (int y = 0; y < bmpData.Height; y++) { int srcX = srcRect.X; int srcY = srcRect.Y + y; int dstX = 0; int dstY = y; var dstPtr = (byte *)bmpData.Scan0 + dstY * bmpData.Stride; var srcRow = pixels.GetPixelByteRowSpan(srcY)[srcX..];
internal static bool CheckBounds(this IReadOnlyPixelRowsContext context, Rectangle sourceRectangle) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Pixels.GetBounds() == sourceRectangle) { return(true); } ImagingArgumentGuard.AssertRectangleInSource(context, sourceRectangle, nameof(sourceRectangle)); return(false); }