public static unsafe Bitmap ToBitmap(this IReadOnlyImageByte <RgbImageType> @this) { var answer = Bitmap.CreateBitmap(@this.Width(), @this.Height(), Bitmap.Config.Argb8888); var step = @this.Step; var dimensions = @this.Dimensions; using (var pin = @this.Open()) { var ptr = pin.Ptr; for (var j = 0; j < dimensions.Y; j++) { var pixelPtr = ptr; for (var i = 0; i < dimensions.X; i++) { var colour = Color.Rgb(pixelPtr[0], pixelPtr[1], pixelPtr[2]); answer.SetPixel(i, j, colour); pixelPtr += step.X; } ptr += step.Y; } } return(answer); }
public static unsafe Bitmap ToBitmap(this IReadOnlyImageByte <MonoImageType> @this) { var answer = Bitmap.CreateBitmap(@this.Width(), @this.Height(), Bitmap.Config.Alpha8); var step = @this.Step; var dimensions = @this.Dimensions; using (var pin = @this.Open()) { var ptr = pin.Ptr; for (var j = 0; j < dimensions.Y; j++) { var pixelPtr = ptr; for (var i = 0; i < dimensions.X; i++) { var colour = Color.Argb(alpha: *pixelPtr, red: 0, blue: 0, green: 0); answer.SetPixel(i, j, colour); pixelPtr += step.X; } ptr += step.Y; } } return(answer); }
public static unsafe Bitmap ToBitmap(this IReadOnlyImageByte <MonoImageType> @this) { var answer = new Bitmap(@this.Width(), @this.Height()); var step = @this.Step; var dimensions = @this.Dimensions; using (var pin = @this.Open()) { var ptr = pin.Ptr; for (var j = 0; j < dimensions.Y; j++) { var pixelPtr = ptr; for (var i = 0; i < dimensions.X; i++) { var colour = Color.FromArgb(*pixelPtr, *pixelPtr, *pixelPtr); answer.SetPixel(i, j, colour); pixelPtr += step.X; } ptr += step.Y; } } return(answer); }
public static unsafe IImageFloat <TType> ToFloatNormalized <TType>(this IReadOnlyImageByte <TType> @this) where TType : IImageType, new() { var answer = new ImageFloat <TType>(@this.Dimensions); var inStep = @this.Step; var outStep = answer.Step; var dimensions = @this.Dimensions; var channelsCount = Singleton <TType> .Instance.ChannelsCount; using (var pinInput = @this.Open()) { using (var pinOutput = answer.Open()) { var inPtr = pinInput.Ptr; var outPtr = pinOutput.Ptr; for (var j = 0; j < dimensions.Y; j++) { var inPixelPtr = inPtr; var outPixelPtr = outPtr; for (var i = 0; i < dimensions.X; i++) { for (var c = 0; c < channelsCount; c++) { outPixelPtr[c] = inPixelPtr[c] / 255f; } inPixelPtr += inStep.X; outPixelPtr += outStep.X; } inPtr += inStep.Y; outPtr += outStep.Y; } } } return(answer); }