I don't see where you set-up your canvas in order to get width and height. Basically you call the method on a empty canvas. A solution would be to first give it's dimension, or use the method calls...