/// <summary> /// Render the Mandelbrot Set /// </summary> /// <param name="bitmapSize">The size of the Bitmap to create</param> /// <param name="imageInfo">The information required to render the desired portion of the Mandelbrot Set</param> /// <param name="progressBar">The <see cref="IProgressBar"/> to use.</param> /// <returns></returns> public static Bitmap Render(Size bitmapSize, ImageInfo imageInfo, IProgressBar progressBar, bool reportProgress) { var bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format32bppRgb); var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var bitmapData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat); var pointer = bitmapData.Scan0; int size = Math.Abs(bitmapData.Stride) * bitmap.Height; byte[] pixels = new byte[size]; Marshal.Copy(pointer, pixels, 0, size); var actions = CreateActions(pixels, bitmapSize, imageInfo, progressBar, reportProgress); Parallel.Invoke(actions); Marshal.Copy(pixels, 0, pointer, size); bitmap.UnlockBits(bitmapData); if (reportProgress) { progressBar.OnProgressFinish(); CalculatedRows = 0; } return(bitmap); }