3 people like it.
Like the snippet!
BMP writer
Write BMP in ARGB uncompressed 32-bits per-pixel format
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
|
open System.IO
/// Writes BMP binary data
let write (writer:BinaryWriter) (pixels:int[][]) =
let height = pixels.Length
let width = pixels.[0].Length
let sizeOfBmpHeader = 14
let sizeOfDibHeader = 108
// BMP Header
writer.Write("BM"B)
writer.Write(sizeOfBmpHeader+sizeOfDibHeader+(4*width*height))
writer.Write([|0uy;0uy|])
writer.Write([|0uy;0uy|])
writer.Write(sizeOfBmpHeader+sizeOfDibHeader)
// DIB Header
writer.Write(sizeOfDibHeader)
writer.Write(width)
writer.Write(height)
writer.Write(1us)
writer.Write(32us)
writer.Write(3)
writer.Write(width*height*4)
writer.Write(2835)
writer.Write(2835)
writer.Write(0)
writer.Write(0)
writer.Write(0x00ff0000)
writer.Write(0x0000ff00)
writer.Write(0x000000ff)
writer.Write(0xff000000)
writer.Write("Win "B |> Array.rev)
writer.Write(Array.create 0x24 0uy)
writer.Write(0)
writer.Write(0)
writer.Write(0)
// Pixel Array
for i = pixels.Length-1 downto 0 do
let row = pixels.[i]
for pixel in row do
writer.Write(pixel)
|
namespace System
namespace System.IO
val write : writer:BinaryWriter -> pixels:int [] [] -> unit
Full name: Script.write
Writes BMP binary data
val writer : BinaryWriter
Multiple items
type BinaryWriter =
new : output:Stream -> BinaryWriter + 1 overload
member BaseStream : Stream
member Close : unit -> unit
member Dispose : unit -> unit
member Flush : unit -> unit
member Seek : offset:int * origin:SeekOrigin -> int64
member Write : value:bool -> unit + 17 overloads
static val Null : BinaryWriter
Full name: System.IO.BinaryWriter
--------------------
BinaryWriter(output: Stream) : unit
BinaryWriter(output: Stream, encoding: System.Text.Encoding) : unit
val pixels : int [] []
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
val height : int
property System.Array.Length: int
val width : int
val sizeOfBmpHeader : int
val sizeOfDibHeader : int
BinaryWriter.Write(value: string) : unit
(+0 other overloads)
BinaryWriter.Write(value: float32) : unit
(+0 other overloads)
BinaryWriter.Write(value: uint64) : unit
(+0 other overloads)
BinaryWriter.Write(value: int64) : unit
(+0 other overloads)
BinaryWriter.Write(value: uint32) : unit
(+0 other overloads)
BinaryWriter.Write(value: int) : unit
(+0 other overloads)
BinaryWriter.Write(value: uint16) : unit
(+0 other overloads)
BinaryWriter.Write(value: int16) : unit
(+0 other overloads)
BinaryWriter.Write(value: decimal) : unit
(+0 other overloads)
BinaryWriter.Write(value: float) : unit
(+0 other overloads)
module Array
from Microsoft.FSharp.Collections
val rev : array:'T [] -> 'T []
Full name: Microsoft.FSharp.Collections.Array.rev
val create : count:int -> value:'T -> 'T []
Full name: Microsoft.FSharp.Collections.Array.create
val i : int
val row : int []
val pixel : int
More information