I have a region object, which has to be resized. It needs to be 20px smaller from every border. However the Region.nearby() function does only accept positive integer values, so the region can only become bigger, not smaller.
Is there any other function for resizing a region or a workaround to pass even negative integers to the function?

有帮助吗?

解决方案

You could define the X,Y,H,W of the new region based on the old region with something like this:

oldRegion = SomeRegionYouAlreadyDefined
oldRegion.highlight(2) 
newRegion = Region((oldRegion.getX() + 20), (oldRegion.getY() + 20), (oldRegion.getW() - 40), (oldRegion.getH() - 40))
newRegion.highlight(2)

Of course, you can remove the .highlight() lines. That's just for ease of seeing where your regions are.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top