Daniel, In your sample code, you might try using the ctx.Response.End(); method instead of the ctx.Response.Close();. Once you send the image data back to the client side, you should end the current request by aborting the current thread. Also, is it necessary to create an instance of the Image type? Since you can simply write out the binary data of the image to output stream of the Response object as below:
ctx.Response.OutputStream.Write(data, 0, data.Length);