{{indexmenu_n>999}}
====== New ======
###
//b = BitMap.New(NX, NY, Options)// returns a new [[documentation:language_reference:objects:bitmap:start|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 [[documentation:language_reference:objects:graphics:start|Graphics object]] with //[[documentation:language_reference:objects:graphics:functions:add|Graphics.Add()]]//.
###
===== Input =====
* //NX// : Integer, the number of pixels in a row, the width of the bitmap.
* //NY// : Integer, the number of pixels in a column, the height of the bitmap.
* Options : (optional) A table of options. Possible options are:
* //"Canvas.Origin.X"//, //"Canvas.Origin.Y"// : Reals, the lower left corner of the bitmap on the page, as a fraction of the width and of the height of the page. Default values 0 and 0
* //"Canvas.Size.X"//, //"Canvas.Size.Y"// : Reals, the width and the height of the bitmap on the page, as a fraction of the width and of the height of the page. Default values 1 and 1, the whole page
* //"Color"// : 32 bit integer 0xAARRGGBB, the color of all pixels. Default value 0xFFFFFF (opaque white)
* //"alpha"// : Integer from 0 to 255, the opacity, on top of the transparency of //"Color"//: 255 keeps the color as it is, 128 makes an opaque color half transparent and 0 fully transparent. Default value 255
===== Output =====
* //b// : a BitMap object.
===== Example =====
###
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.
###
==== Input ====
-- 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()
==== Result ====
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:
###
{{:documentation:language_reference:objects:bitmap:functions:bitmap_new.png?nolink&400 |}}
===== Table of contents =====
{{indexmenu>../#2|tsort}}