public static Image <TPixel> WrapMemory <TPixel>( Memory <byte> memory, Size size, int?byteStride = null) where TPixel : unmanaged, IPixel <TPixel> { ArgumentGuard.AssertDimensionsGreaterThanZero(size, nameof(size)); ImagingArgumentGuard.AssertContigousLargeEnough(memory.Length, size.Area, nameof(memory)); int stride = byteStride ?? (size.Width * Unsafe.SizeOf <TPixel>()); AssertValidStride <TPixel>(size, memory.Length, stride, nameof(byteStride)); AssertValidMemory(size, memory.Length, stride, nameof(memory)); var buffer = new Image <TPixel> .PixelBuffer(memory, stride); return(new Image <TPixel>(buffer, size)); }
public static Image <TPixel> WrapMemory <TPixel>( IMemory memory, Size size, bool leaveOpen = false, int?byteStride = null) where TPixel : unmanaged, IPixel <TPixel> { if (memory == null) { throw new ArgumentNullException(nameof(memory)); } ArgumentGuard.AssertDimensionsGreaterThanZero(size, nameof(size)); ImagingArgumentGuard.AssertContigousLargeEnough(memory.Length, size.Area, nameof(memory)); int stride = byteStride ?? (size.Width * Unsafe.SizeOf <TPixel>()); AssertValidStride <TPixel>(size, memory.Length * memory.ElementSize, stride, nameof(byteStride)); AssertValidMemory(size, memory.Length * memory.ElementSize, stride, nameof(memory)); var buffer = new Image <TPixel> .PixelBuffer(memory, stride, leaveOpen); return(new Image <TPixel>(buffer, size)); }