I'm building this as part of a larger class to rapidly search for smaller images inside larger images. This is my first serious F# project so comments especially concerning style and organization are appreciated.
module imagesearch =
type BitmapSearchClass() =
// Largely inspired by this article
// http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx
static member loadBitmapIntoArray (pBitmap:Bitmap) =
let tBitmapRectangle = Rectangle(0, 0, pBitmap.Width, pBitmap.Height)
let tLockMode = ImageLockMode.ReadOnly
let tImageFormat = PixelFormat.Format24bppRgb
let tBitmapData = pBitmap.LockBits(tBitmapRectangle, tLockMode, tImageFormat)
let tIntPtr = tBitmapData.Scan0
let tImageByteLength = Math.Abs(tBitmapData.Stride) * pBitmap.Height
// Zerocreate creates the "empty" array
let tImageRGBValues : byte array = Array.zeroCreate tImageByteLength
do Marshal.Copy(tImageRGBValues, 0, tIntPtr, tImageByteLength)
do pBitmap.UnlockBits(tBitmapData)
tImageRGBValues, pBitmap.Width, pBitmap.Height
Current state of the module is below
module ImageSearch =
type BitmapSearch() =
// Largely inspired by this article
// http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx
static member LoadBitmapIntoArray (pBitmap:Bitmap) =
let tBitmapData = pBitmap.LockBits( Rectangle(Point.Empty, pBitmap.Size),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb )
let tImageArrayLength = Math.Abs(tBitmapData.Stride) * pBitmap.Height
let tImageDataArray = Array.zeroCreate<byte> tImageArrayLength
Marshal.Copy(tImageDataArray, 0, tBitmapData.Scan0, tImageArrayLength)
pBitmap.UnlockBits(tBitmapData)
tImageDataArray, pBitmap.Width, pBitmap.Height