Monthly Archives: May 2014

Capture screen under Mac OS with Mono Development

I am doing a project that need to capture screen of Mac OS through Mono Development. I found a post in stackoverflow described same thing as I want to do. The OP in the post said he is failed to do that. Someone replied that the posted code only worked under Linux but not Mac OS. However I tried to use same code in my project and it is succeeded. Below is a screenshot I took. Not sure why. My Mac OS: 10.9, Mavericks.

Screenshot

Below is the code

Gdk.Window window = Gdk.Global.DefaultRootWindow;
if (window!=null)
{
    Gdk.Pixbuf pixBuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, window.Screen.Width, window.Screen.Height);
    pixBuf.GetFromDrawable(window, Gdk.Colormap.System, 0, 0, 0, 0, window.Screen.Width, window.Screen.Height);
    pixBuf.ScaleSimple(400, 300, Gdk.InterpType.Bilinear);
    pixBuf.Save("screenshot0.jpeg", "jpeg");
}

I tried to reply same as above to the stackoverflow post, but it has been deleted because “it is no helpful to resolve this issue”. 😦

Advertisements