b = BitMap.New(NX, NY, Options) returns a new BitMap object of NX by NY pixels, all of one color, by default opaque white. The options set the color and the rectangle of the page the bitmap fills when it is put on a Graphics object with Graphics.Add().
Three bitmaps on one page: an opaque white one that fills the page, a half transparent red one and a blue one made half transparent by “alpha”. The script prints where each bitmap lies on the page and the color of its first pixel, as Graphics.ToTable gives them.
-- a bitmap of 200 by 100 pixels, opaque white, that fills the whole page it is put on b1 = BitMap.New(200, 100) -- a bitmap of 20 by 20 pixels, half transparent red, from (0.1, 0.2) to (0.5, 0.8) of the page b2 = BitMap.New(20, 20, {{"Canvas.Origin.X",0.1}, {"Canvas.Origin.Y",0.2}, {"Canvas.Size.X",0.4}, {"Canvas.Size.Y",0.6}, {"Color",0x80FF0000}}) -- the same in blue, made half transparent by the opacity alpha, from (0.3, 0.1) to (0.9, 0.5) b3 = BitMap.New(20, 20, {{"Canvas.Origin.X",0.3}, {"Canvas.Origin.Y",0.1}, {"Canvas.Size.X",0.6}, {"Canvas.Size.Y",0.4}, {"Color",0x0000FF}, {"alpha",128}}) -- put them on a page and look at what is there: the corners and the color of the first pixel pl = Graphics.New() pl.Add(b1) pl.Add(b2) pl.Add(b3) for k, B in ipairs(Graphics.ToTable(pl).BitMap) do print(string.format("bitmap %d: %3d by %3d pixels from (%.1f, %.1f) to (%.1f, %.1f), first pixel 0x%s", k, B.NpointsX, B.NpointsY, B.LB[1], B.LB[2], B.RT[1], B.RT[2], string.sub(B.Pixels, 1, 8))) end file = io.open("BitMap_New.svg", "w") file:write(Graphics.ToSVG(pl, {{"RelativeSize",true}})) file:close()
bitmap 1: 200 by 100 pixels from (0.0, 0.0) to (1.0, 1.0), first pixel 0x00FFFFFF bitmap 2: 20 by 20 pixels from (0.1, 0.2) to (0.5, 0.8), first pixel 0x80FF0000 bitmap 3: 20 by 20 pixels from (0.3, 0.1) to (0.9, 0.5), first pixel 0x7F0000FF
The opacity 128 of “alpha” gives the transparency 0x7F. The script writes BitMap_New.svg; the white bitmap is the white background of the page: