private Image CreateRenderThreads(Size size,Area area) { Bitmap image = new Bitmap(size.Width,size.Height); BitmapEditor editor = new BitmapEditor(image); int[] ranges = GetRangesPixelsArray(size.Width,RenderSettings.NumberOfThreads); Thread[] threads = new Thread[RenderSettings.NumberOfThreads]; editor.LockBits(); for (int i = 0; i < RenderSettings.NumberOfThreads; i++) { threads[i] = new Thread(new ParameterizedThreadStart(ProcessBitmapPart)); threads[i].IsBackground = true; threads[i].Priority = RenderSettings.ThreadsPriority; threads[i].Start(new ThreadData() { areaPlain = area, imageSize = size, widthStart = ranges[i], widthEnd = ranges[i+1], editorReference = editor }); } foreach (var t in threads) { t.Join(); } editor.UnlockBits(); return image; }
protected Image RenderImage(Size size,Area area) { Image fractalImage; _widthRatio = (area.End.X - area.Start.X)/size.Width; _heightRatio = (area.End.Y - area.Start.Y)/size.Height; _renderAsyncIterations = 0; var startClock = DateTime.Now; if(_singleIterationMode) { fractalImage = SingleIterationRender(size,area); } else { fractalImage = CreateRenderThreads(size,area); } var renderTime = DateTime.Now - startClock; if(RenderCompleteCall != null) RenderCompleteCall(renderTime); return fractalImage; }
private Image SingleIterationRender(Size size,Area area) { Bitmap image = new Bitmap(size.Width,size.Height); Graphics.FromImage(image).FillRectangle(new SolidBrush(_backgroundColor),0,0,size.Width,size.Height); BitmapEditor editor = new BitmapEditor(image); double realPart,imaginaryPart; editor.LockBits(); for (int i = 0; i < size.Height; i++) { for (int r = 0; r < size.Width; r++) { realPart = (r*_widthRatio) + area.Start.X; imaginaryPart = (i* _heightRatio) + area.Start.Y; if(Contains(realPart,imaginaryPart,_accuracy)) { editor.SetPixel(r,i,_fractalColor); } } if(RenderProgressCall != null) { RenderProgressCall(i,size.Height); } } editor.UnlockBits(); return image; }
private Area GetNewArea(Point p1,Point p2) { Point[] points = CreateAreaPoints(p1, p2); double xRatio = (_renderProperties.Area.End.X - _renderProperties.Area.Start.X) / _renderProperties.Width; double yRatio = (_renderProperties.Area.End.Y - _renderProperties.Area.Start.Y) / _renderProperties.Height; Area newArea = new Area ( new Area.Point(xRatio * points[0].X + _renderProperties.StartX, yRatio * points[0].Y + _renderProperties.StartY), new Area.Point(xRatio * points[1].X + _renderProperties.StartX, yRatio * points[1].Y + _renderProperties.StartY) ); return newArea; }