Originally Posted by
cbeginner12334
hello guys i need to make a bmp file of plot xy
those anyone has a little idea how i can do it ?
TNx
Go to my website and download bmp.c from the BabyX resource compiler. This contains a function for saving an array as a .bmp
file.
Now your problem is to create the plot as a raster.
In C, it's usually easier to treat 2D arrays as 1D arrays, and do the
indexing manually. That's because C's 2D arrays aren't good if
the dimensions need to be flexible, which is usually the case.
So set the whole buffer to your background colour, probably white.
Now iterate over the x range, of your array. Say the bitmap is
256 x 256. iterate from xi = 0 to 255.
Now convert xi (pixel x) to x (logical x). Say your plot goes from 0
to 1. logical x equals x1 / 255.0.
Now calculate logical y, based on your function. say you are plotting
x squared, logical y - logical x * logical x.
Now convert logical y to pixel y. This is a similar operation to
calculating logical x from pixel x, but in reverse.
Now set the pixel to red, using the formula
Code:
buffer[ iy * width +x] = RED;