How can I get the pixel length (in bytes) from the PixelFormat enumeration? I want to process the pixels of the image using my own approach, but how can I iterate over the image if I don't know the pixel offsets.
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
source share