Sure, but AFAIK a green card is more like indefinate leave to remain: it's not a visa as such, but a thing you can apply for after you have already lived in the country for some amount of time (on a visa of some other form, generally one which allows you to legally stay for the required time in the country) which gives the right to stay permanently. So it doesn't make a lot of sense to require leaving the country to apply first.