Either way, the divergence theorem

is behind it all.
Here are the two ways:

Here, it is assumed that as you travel from (x,y), the normal vector in question is always to your left. (Doesn't sound right, does it?) If this is not the case: switch the start and finish points, and then it will be!
For more on this method (especially if that sounded wrong!), see the section of notes in which the perp operation is used to realate normal and tangential linte integrals. Now all you have to do is find the function f ...