我怎样才能得到的的PixelFormat 枚举? 我要处理图像的像素使用原生的做法,但如何通过图像循环,如果我不知道像素的偏移量。
code:
让formRgbCube(图片:位图)=
让宽度= image.Width
让身高= image.Height
让我们的位图数据= image.LockBits(矩形(0,0,image.Width,image.Height),ImageLockMode.ReadOnly,image.PixelFormat)
让PTR = NativePtr.ofNativeInt<字节>(bitmapData.Scan0)
让跨距= bitmapData.Stride
让rgbCube = Array3D.zeroCreate×宽×高3
对于i = 0至宽度 - 1做
对于j = 0身高 - 1做
对于k = 0至2 DO
。rgbCube [I,J,K]其中; - NativePtr.read&其中;字节>(NativePtr.add PTR(步幅* J + I * 3(*为24ppb *)+ K的一例))
rgbCube
解决方案
Image.GetPixelFormatSize(image.PixelFormat);
返回的颜色深度,在每个像素的比特数,指定的 像素格式。 - 文档
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