- /// ------------------------------------------------------------------------
- /// <summary>
- /// Draw the fractal (with unmanaged code).
- /// </summary>
- /// ------------------------------------------------------------------------
- public void DrawMandelBrotFractalUnmanaged()
- {
- int width = this.Width;
- int height = this.Height;
- int offset = width % 4;
-
- int halfX = 2 * width;
- int halfY = height / 2;
-
- using (Graphics gfx = this.CreateGraphics())
- {
- this._bmpBuffer = new Bitmap(width, height, gfx);
- BitmapData bmpData = this._bmpBuffer.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
-
- unsafe
- {
- byte* newPixel = (byte*)(void*)bmpData.Scan0;
- width *= 3;
-
- for (int y = 0; y < height; ++y)
- {
- for (int x = 0; x < width; x += 3)
- {
- Complex complex = new Complex((x - halfX) / 450d, (y - halfY) / 150d);
- Color color = this.GetColor(this.GetStep(complex));
- newPixel[0] = color.B;
- newPixel[1] = color.G;
- newPixel[2] = color.R;
- newPixel += 3;
- }
- newPixel += offset;
- }
- }
- this._bmpBuffer.UnlockBits(bmpData);
- Graphics.FromImage(this._bmpBuffer).DrawString("Mandelbrot's Fractal", this._font, this._fontBrush, Point.Empty);
- gfx.DrawImage(this._bmpBuffer, Point.Empty);
- }
- }
/// ------------------------------------------------------------------------
/// <summary>
/// Draw the fractal (with unmanaged code).
/// </summary>
/// ------------------------------------------------------------------------
public void DrawMandelBrotFractalUnmanaged()
{
int width = this.Width;
int height = this.Height;
int offset = width % 4;
int halfX = 2 * width;
int halfY = height / 2;
using (Graphics gfx = this.CreateGraphics())
{
this._bmpBuffer = new Bitmap(width, height, gfx);
BitmapData bmpData = this._bmpBuffer.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
unsafe
{
byte* newPixel = (byte*)(void*)bmpData.Scan0;
width *= 3;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; x += 3)
{
Complex complex = new Complex((x - halfX) / 450d, (y - halfY) / 150d);
Color color = this.GetColor(this.GetStep(complex));
newPixel[0] = color.B;
newPixel[1] = color.G;
newPixel[2] = color.R;
newPixel += 3;
}
newPixel += offset;
}
}
this._bmpBuffer.UnlockBits(bmpData);
Graphics.FromImage(this._bmpBuffer).DrawString("Mandelbrot's Fractal", this._font, this._fontBrush, Point.Empty);
gfx.DrawImage(this._bmpBuffer, Point.Empty);
}
}