Fixed memory leak

Two calls of BeginImageContext are done but only one Close is called. This is actually not necessary to open the second context because we can reuse what is already in the first one to generate the second image.