How can i get pixel length (in bytes) from PixelFormat enumeration? I want to process image pixels using native approach, but how can i iterate through an image if i don't know pixel's offset.
Code:
let formRgbCube (image : Bitmap) =
let width = image.Width
let height = image.Height
let bitmapData = image.LockBits(Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat)
let ptr = NativePtr.ofNativeInt<byte>(bitmapData.Scan0)
let stride = bitmapData.Stride
let rgbCube = Array3D.zeroCreate width height 3
for i = 0 to width - 1 do
for j = 0 to height - 1 do
for k = 0 to 2 do
rgbCube.[i, j, k] <- NativePtr.read<byte>(NativePtr.add ptr (stride * j + i * 3(*an example for 24ppb*) + k))
rgbCube
Image.GetPixelFormatSize(image.PixelFormat);
Returns the color depth, in number of bits per pixel, of the specified pixel format. -- Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With