Any built-in Android function to wrap Canvas drawing?

I’m using Canvas to draw on Bitmap.

Consider this is my bitmap (dots are just empty space, x marks the spot):

........
......x.
........
........
........

If I draw this box:

###
###
###

starting at x, I’d get this:

........
......##(#)
......##(#)
......##(#)
........

But I want those “leaky” #s to be drawn on the far left, as if this bitmap was wrapped. Like Pac-Man.

So basically, what I’d like is some way to instruct Canvas not to draw pixels at (x, y) but (x % width, y % height). Any simple way to achieve this?

Another example, let’s say I want to draw the same 3×3 box/square starting at (width – 1, height – 1), then I want to get this:

##.....#
##.....#
........
........
##.....#

Answer

As far as I can tell from the docs there is no built-in function that will let you achieve what you are looking for. Since you are dealing directly with a canvas object the assumption is that the app would handle all of the pixel level drawing information.

Like you mentioned there is more than one way to do it in the app but unfortunately none out of the box.

Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .