Get depth buffer without color to image

I have a task:
Get a depth buffer(z-buffer) and save it to image.

I tried to get depth buffer from viewController. But it gives me an array with color info. And i don`t need “screenshot”. I need only black-white depth info.

So i ask you for a help. Maybe i need to look somewhere in a sources of an engine, and get it there?