[C#] Bitmap imaging

Soldato
Joined
12 Apr 2004
Posts
11,788
Location
Somewhere
I've been playing around with fractal patterns in C# and I've built a program to render the Mandelbrot set, which involves rendering the pattern on a pixel-by-pixel basis (the algorithm i've written does this randomly to produce a nice effect :p).

Currently I'm using a Bitmap object and using the method SetPixel() to set the colour of each pixel individually, however this seems to be a very slow way of doing it... is there any better way? :confused:

Cheers :)
 
Last edited:
Well, setting each pixel individually is obviously the only war of doing it, but I was just wondering if there was a more efficient way of doing that than the Bitmap/SetPixel() method.
 
Thanks for the help! Haven't had time to try any of your suggestions out yet... I'll have a look at the LockBits() method I think... seems to require unsafe code though...

In the mean time, have a Mandelbrot image :D
http://img115.imageshack.us/img115/9400/mandelbrot7zw.png

Still only does monochrome, and looks a bit messy as it's not anti-aliased. Does anyone have any idea how I could anti-alias it? :confused:
 
I've tried setting them to 65536, and here is the result:
http://img99.imageshack.us/img99/5715/mandelbrotimage6cx.png

Seems to have helped a bit, but it still looks messy. Also, the higher the iteration count, the darker the image seems to become. I can overcome this by increasing the radiance (which amplifies the brightness of each pixel finding (iterationCount/iterationLimit)^(1 - radiance) * 255). Hower, this seems to reduce the contrast somewhat, especially at very high numbers of iterations. :confused:
 
You'd think so, but unless you're doing a stupidly high number of iterations, the time to plot each pixel does actually have a noticeable impact on the overall generation time.

For example, plotting a 300x300 square (of a solid colour) in C# using the method I mentioned, pixel by pixel, takes around 3-5 seconds.

robmiller said:
Does PHP feel limiting now? :D
Well it is only a web scripting language :p
 
It's certainly very rewarding to get visual results from your hard work :)
That LockBits method also meant I got to play around with unsafe code /evilgrin :D
 
Massive improvement - at least 10 times faster :)
Out of interest, would it be best to lock a 1x1 Rectangle into memory for each pixel, or should I just lock the entire image into memory and keep using the same BitmapData object every time I set a pixel?
 
Last edited:
Back
Top Bottom