display.newMaskBitmap(w,h) or graphics.newMaskBitmap(w,h)

Instead of having to create masks for display objects and widgets, the ability to create them in memory on the fly. This would be especially helpful on devices with varying screen sizes.

Calling this function would return a object that is a solid white bitmap of the width and height, with a black four pixel border. The resulting object would mimic a loaded file.

It could be used in the following ways:

To create:
local objMask = display.newMaxBitmap(208,208)
or objMask = graphics.newMaskBitmap(208,208)

The resulting bitmap would be 200x200 white space with 4PX black along top, right, bottom, and left.
Examples of use:
myGraphic:setMask( objMask )

local listOptions = {
top = display.statusBarHeight,
height = 410,
maskFile = objMask
}

local scrollView = widget.newScrollView{
width = 320
height = 320,
scrollWidth = 768,
scrollHeight = 1024,
maskFile=objMask,
listener = scrollViewListener
}

[import]uid: 13784 topic_id: 23270 reply_id: 323270[/import]

+1 [import]uid: 61899 topic_id: 23270 reply_id: 93313[/import]

You can do this via lua, however with the new culling features it wont work if your creating a mask that exceeds the screens width/height.

If your using the stable build it will work though, or if you want to create masks that are not going to exceed the screens width/height.

I haven’t tested applying this created mask to an object, i imagine it will work though

[code]
–Sample usage for tar module
–By Danny @ anscamobile

– Sample code is MIT licensed – Copyright © 2011 InfusedDreams. All Rights Reserved.

–Function to create a mask file
local function createMask(width, height, name)
local cW = display.contentWidth
local cH = display.contentHeight
local maskGroup = display.newGroup()

local blackRect = display.newRect(10, 10, width + 4, height + 4)
blackRect.x = cW * 0.5
blackRect.y = cH * 0.5
blackRect:setFillColor(0, 0, 0)
maskGroup:insert(blackRect)

local whiteRect = display.newRect(10, 10, width, height)
whiteRect.x = blackRect.x
whiteRect.y = blackRect.y
whiteRect:setFillColor(255, 255, 255)

maskGroup:insert(whiteRect)

local baseDir = system.DocumentsDirectory
display.save(maskGroup, name … “.jpg”, baseDir )

display.remove(maskGroup)
end

–Create a mask
createMask(1000, 1000, “mask-100x100”)
[/code] [import]uid: 84637 topic_id: 23270 reply_id: 93357[/import]