GraphicImage Template
setClipRegion()
Limit drawing functions to a subset of the entire image
Syntax
GraphicImage = rb.GraphicImage.setClipRegion(top_left, bottom_right)
Parameters
The 'setClipRegion' method takes 2 parameters:
Name | Type/Value | Range/Length | Description | top_left | struct Point | see definition | Optional, default = {x:0,y:0}
Coordinates of the top-left of the clip region
| bottom_right | struct Point | see definition | Optional, default = {x:image.width,y:image.height}
Coordinates of the bottom-right of the clip region
|
Results
The 'setClipRegion' method returns GraphicImage:
Type/Value | Range/Length | Description |
GraphicImage |
  |
Return a reference to the GraphicImage (to 'this')
|
Remarks By default drawing operations can change any area of the destination
image. For those occassions where you want to restrict drawing to a
specific area, for example within a frame, you can use
setClipRegion. To subsequently clear the restriction, simply call setClipRegion with
no parameters. Example Load a 'frame' and then write some text within the border - making sure the 10 pixel
border is not over-written :
// Create an empty 100x100 pixel palette based image
var border = (new GraphicImage).make('/images/border.gif','image/gif');
// Set clip region to avoid the 10 pixel border all the way round the image
border.setClipRegion({x:10,y:10},{x:border.width-20, y:border.height-20});
// Write some text
var r = rimg.drawText("Hello World",{x:40,y:40},"/fonts/comic.ttf",20,0x202020);
|