Hi All,

I am working on a Mandelbrot. I can draw the Mandelbrot to a bitmap and then paste it on the form. What I WANT to be able to do is when the user drags their mouse over an area, it redraws the Mandelbrot with the x and y coordinates.

I have written all the code correctly (to my knowledge) and there are no errors (until I run it). However I've debugged and I can take the users mouse values fine, the error I receive is when I try to re-draw a line.

I believe the problem is to be with how my graphics and bitmap are defined. Does anyone have any suggestions?

Here are some code snippets, full code available on request (message me).

Painting bitmap to the form on load

private void Form1_Paint(object sender, PaintEventArgs e)
        {
            g1 = e.Graphics;

            g1.DrawImage(myBitmap, 0, 0, x1, y1);

            g1.Dispose();
        }

Declaring g1 and bitmap

private Graphics g1;
private System.Drawing.Bitmap myBitmap;

Defining g1 and bitmap

myBitmap = new Bitmap(x1, y1);
g1 = Graphics.FromImage(myBitmap);

Mandelbrot Method

private void mandelbrot() // calculate all points
        {
            int x, y;
            float h, b, alt = 0.0f;

            action = false;
       

            Color color = Color.Black;
            Pen pen = new Pen(color);

            for (x = 0; x < x1; x += 2)
                for (y = 0; y < y1; y++)
                {
                    // get colour value for this x,y point
                    h = pointcolour(xstart + xzoom * (double)x, ystart + yzoom * (double)y);
                    // if colour value changed then calculate new colour
                    if (h != alt)
                    {
                        // calculate brightness
                        b = 1.0f - h * h;
                        // calculate colour from HSB
                        color = HSBColor.FromHSB(new HSBColor(h * 255, 0.8f * 255, b * 255));
                        // get drawing pen for this colour
                        pen = new Pen(color);
                        // keep track of last colour value
                        alt = h;
                    }
                    g1.DrawLine(pen, x, y, x + 1, y);
                }
         
            action = true;
        }

The problem is that when I try to re-enter the Mandelbrot method, on the line "g1.DrawLine(pen, x, y, x + 1, y);" I receive the error "ArgumentException was unhandled". Even if I run the line with basic values that aren't defined from the other code sections i.e:

g1.DrawLine(new Pen(Color.Green), 225, 225, 350, 350);

I receive this error.

Like I said earlier I think it's because the I'm trying to redraw to the bitmap! However I'm REALLY stuck and would appreciate any help :)

OK I have actually fixed this :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.