I am an artist with limited computer knowledge (but I am able to compile
some code) who needs for a project I am working on a way to read in a bmp
file, loop through the pixels and store their rgb value in a file in the
format (x, y, r, g, b). I want to use these values as the basis for some
paintings.
I looked around on the internet to find some code, but my skills are just
not enough to do something useful with what I have found. Unfortunately,
images are rather large, so I need a way to automaise this. I am sure that
there is somebody out there who could do this very quickly (or has some code
already). It would mean a lot to me - since I am increasingly stuck with
this and nobody I know seems to be able to help me.
If you are trying to make sense of some C code, and the question is
about the C language (and not about and graphics library APIs that the
program is using), then you can post the confusing portion here and
someone may be able to explain it to you.
If you are trying to make sense of some graphics library APIs,
then you are better off asking in a graphics newsgroup. Perhaps
comp.graphics.misc as a starting point, and they may be able to answer
your question or point you to a more specific group.
If you are coding up your project and you run into a C related problem
that you cannot figure out for yourself, first see if your problem is a
frequently asked question:
http://www.eskimo.com/~scs/C-faq/top.html
If not, then you can post what you have here and ask what is wrong.
However, if your question is about how to use a graphics library API,
then you will be redirected to a graphics newsgroup.
Generally speaking, when you read in a bitmap file, you will need to
know the file format. The file format will tell you how each pixel
in the bitmap file is encoded. For example, perhaps the bitmap file
is encoded like:
XDIM, YDIM
COLOR_1_1, COLOR_2_1, ... COLOR_XDIM_1
COLOR_1_2, COLOR_2_2, ... COLOR_XDIM_2
.
.
.
COLOR_1_YDIM, COLOR_2_YDIM, ... COLOR_XDIM_YDIM
Where XDIM and YDIM are scalars describing the dimensions of the bitmap,
and each color consists of #RRGGBB, where each color component is
specified by 2 hexadecimal digits.
So, a 3x3 bitmap would look like:
3, 3
#000000, #FFFFFF, #000000
#FFFFFF, #FFFFFF, #FFFFFF
#000000, #FFFFFF, #000000
Your job would be to write a C program that read in such a file and
converts it to the format you want. To read in the file format above,
you can use calls to the C functions fgets, sscanf, and strtol. You
may want to store each pixed of the bitmap into some data structure
that you will later iterate over to generate your output. Your
data structure may involve using a struct.
Your specification of the output format was not very specific, but it
seemed like:
(1, 1, 0, 0, 0)
(2, 1, 255, 255, 255)
(3, 1, 0, 0, 0)
(1, 2, 255, 255, 255)
(2, 2, 255, 255, 255)
(3, 2, 255, 255, 255)
(1, 3, 0, 0, 0)
(2, 3, 255, 255, 255)
(3, 3, 0, 0, 0)
Each line of output could be generated by a single print statement
using the C function printf.
If you have not already done so, please acquire a good C reference, and
lookup any function or term that I have mentioned that seems unfamiliar
to you.
-- James