Can I render a line around a sprite?

I want to render a line around a sprite like this.
before rendering a line.

after rendering a line.

Is it possible to do this by code?
I absolutely have no idea about how to do this.
Thanks in advance.