public static async Task <byte[]> Download(int imageNo) { // Configuration const int width = 1600; const int height = 800; const int imageCount = 8; // Generate image Console.WriteLine("Render started"); var imageWidth = width / imageCount; var image = new Image(imageWidth, height); using (var pixelAccessor = image.Lock()) { // Raytracer RayTracer rayTracer = new RayTracer(width, height, (int x, int y, ImageProcessorCore.Color color) => { pixelAccessor[x, y] = color; }); // Scene Scene scene = _GenerateScene(((double)height) / ((double)width)); // Render var start = DateTime.Now; rayTracer.RenderPartial(scene, imageNo, imageCount); var end = DateTime.Now; Console.WriteLine($"Render complete. Time: {end - start}"); } // Save and return using (MemoryStream stream = new MemoryStream()) { image.Save(stream); return(stream.ToArray()); } }