Alternative to using Bitmap

G

Guest

I'm a VB.NET newbie. I've created a program that plots pixels at random on
the form. I have a 19" LCD monitor with a resolution set to 1280 by 1024. If
you do the math, that means that there are over 1.3 million pixels. In one
version of the program, the pixels start plotting at the upper-left & go down
the form from top to bottom & left to right. In another version, the pixels
are plotted at random. I have a 2.4 GHZ Athlon 64 with 1 gigabyte of RAM. If
DrawImage is inside the For-Next loop, I can see the pixels being plotted.
It's sooo slooow! If DrawImage is outside of the For-Next loop, I sit & stare
at a blank form until the image is drawn. Unfortunately, there is no Pset or
its .NET equivalent. Microsoft in its infinite wisdom chose to not include
it. I want to be able to create a program that can draw fractals. I know that
fractal calculations are time-consuming. I don't want to have to wait for
hours to see a fractal. Is there a faster way to plot individual pixels
without having to resort to using Bitmap? Remember, I'm a newbie. I don't
want a complicated convoluted way to draw pixels. Can I create an object
that will plot pixels faster than Bitmap or am I out of luck? What is the
Path object? Can I use that to plot individual pixels? Thank you. David
 
S

Steven Nagy

Can you preconstruct your fractal in a rectangular array first, then
draw it as one image?
Pretend a 2D array is your form that you are drawing to. Only draw it
at the end.
 
L

Larry Lard

pcnerd said:
I'm a VB.NET newbie. I've created a program that plots pixels at random on
the form. I have a 19" LCD monitor with a resolution set to 1280 by 1024. If
you do the math, that means that there are over 1.3 million pixels. In one
version of the program, the pixels start plotting at the upper-left & go down
the form from top to bottom & left to right. In another version, the pixels
are plotted at random. I have a 2.4 GHZ Athlon 64 with 1 gigabyte of RAM. If
DrawImage is inside the For-Next loop, I can see the pixels being plotted.
It's sooo slooow!

Show us your code. My own not-particularly-optimised Mandelbrot program
does a full screen of a part of the Mandelbrot set that is half in,
half out, in about 7 seconds on a 3 GHz P4. Note that programs like
this are often much (order of magnitude) quicker when run without the
debuger attached - once there are no known bugs, run with Ctrl+F5
rather than F5 to try this.
If DrawImage is outside of the For-Next loop, I sit & stare
at a blank form until the image is drawn. Unfortunately, there is no Pset or
its .NET equivalent. Microsoft in its infinite wisdom chose to not include
it.

What's Bitmap.SetPixel then?
 
G

Guest

Don't draw the bitmap for every single pixel that you draw. Use a
counter and draw the bitmap for every thousand pixel or something.
 
G

Guest

I haven't done the fractal program yet. I'm still learning VB. So, I can't
show you the code because it doesn't exist. I don't completely understand
fractal math, but I know that the math is time-consuming. I'm still learning
how to plot pixels. Does the managed code & the .NET Framework overhead slow
every thing down? I think that I have a pretty fast PC ( 2.4 GHZ Athlon 64
with 1 gigabyte of RAM). I didn't know about the debugger being attached.
I've been pressing F5. I'll have tp press CTRL + F5 & see if the program runs
faster. Thank you. David
 
G

Guest

Interesting idea. I haven't considered that. It would be a pretty big array.
If it works, it would probably be faster than going thru the hassle of
creating the bitmap & then setting each pixel & then drawing the bitmap. Pset
would make it a whole lot simpler & easier. My LCD monitor has a resolution
of 1280 by 1024. My PC has 1 gigabyte of RAM. Wouldn't a 1280 by 1024 size
array take up a lot of system resources? How would I draw the array? What is
the source code? Wouldn't I have to use nested For-Next loops to access each
element in the array?
 
G

Guest

The array would take up the same amount of memory that a BitMap object
of the same size would.

To draw the array you would create a bitmap, and set the color of each
pixel in the bitmap from the array.

Yes, to reach each element in the array using nested loops is the
easiest way.
 
G

Guest

So, you are telling me that I still have to use the Bitmap object? Creating
an array is an extra step. I don't want it to be complicated. I want it to
be simple. Won't both the array & the Bitmap object exist in memory at the
same time? I was hoping to avoid using the Bitmap. I was hoping that there
was a simpler way to do it. Apparently, there isn't.
 
S

Steven Nagy

Typically, you could assume that if your screen size is 1200 x 1024,
just muliply the 2 to get how many elements in your array (in this
case, around 1.2 million) and then assume each element is an integer
(32 bit to represent your 32bit color) which is 4 bytes. So that means
you have an array with 4 million bytes, or 4mb. You'll find that the
Visual Studio will take at least 30mb ram straight off the bat anyway
so your 4mb array is not so bad.

So then assume you use a bit map to draw it to the screen, the bitmap
only needs to exist during the drawing process. However you could just
draw each pixel manually without using a Bitmap. The Bitmap just makes
it easier to manage, particularly if you want to save the image as a
file later. Bitmap objects can be converted to other types as well so
that your fractal can save as GIF or whatever.

So use an array to create the fractal, then stick it in a bitmap, and
then cleanup the array from memory if you are overly concerned.

Discussion point:
Did you say you have a 64 bit processor? Then perhaps the calculation
will occur faster if you use LONGs instead of INTs. It will take more
RAM, but the calc should be faster because your processer will not need
to do any fancy work to turn your integer calculations into long
calculations. Can anyone provide advice on this? Am I just rambling? It
might be 1 million pixels, but it might be way more than 1 mil
calculations, particularly if fractal math requires multiple recursive
operations.
 
G

Guest

You state "However you could just draw each pixel manually without using a
Bitmap." Finally! This is what I've been trying to do. Microsoft in its
infinite wisdom chose to not include "Pset" in VB.NET. So, how do I draw each
pixel manually? Can you include example source code? Thank you. David
 
S

Steven Nagy

Sorry I'm not currently in a position to open a windows app.
What you need will be found in the System.Drawing and
System.Drawing.Drawing2D namespaces. Its all called GDI+ . There will
be methods that are part of the Graphics class that enable you to draw
rectangles, arcs, circles, lines, etc. There should be one to draw a
dot as well.

You will need to realise though that once you paint it, it isn't a
permanent fixture on the form. If the form refreshes, or something
paints over it (ie another form, alert or whatever) then your drawn
pixels are gone. To get around this, you put your painting instructions
in the OnPaint event of your form/panel/wherever you want to paint to.

Let me know how you get on. I wanted at one stage to write a fractal
generater in .NET but never got around to it. And of course I found a
million of them on the net and decided there was no merit to it. Not
sure if this has been done before, but a newer idea might be to create
3D fractals in DIRECTX... now that would be mind blowing!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top