How to create a bitmap?

P

Prashant

Hi,

I have a huge problem. I have a data file which looks something like
this -:


..1 .5 .9 -1 .2 .5 ......
..2 .9 .1 .4 .3 -1 ......
..2 .4 .5 .7 .6 .2 ......
........
........

Now I have to create a bitmap out of this using C++ and I really dont
know how to do it? Could someone please tell me a way to go about this
or atleast point me in the right direction?

Thanks,
Prashant
 
B

Ben Pfaff

.1 .5 .9 -1 .2 .5 ......
.2 .9 .1 .4 .3 -1 ......
.2 .4 .5 .7 .6 .2 ......
.......
.......

Now I have to create a bitmap out of this using C++ and I really dont
know how to do it? Could someone please tell me a way to go about this
or atleast point me in the right direction?

Questions about C++ should be asked in comp.lang.c++.
But this doesn't seem to be a C++ question either.
Perhaps comp.programming is the right place, but you'll need to
state what you're actually trying to do. It's not obvious how to
translate a bunch of real numbers into a bitmap.
 
E

Eric Sosman

Prashant said:
Hi,

I have a huge problem. I have a data file which looks something like
this -:


.1 .5 .9 -1 .2 .5 ......
.2 .9 .1 .4 .3 -1 ......
.2 .4 .5 .7 .6 .2 ......
.......
.......

Now I have to create a bitmap out of this using C++ and I really dont
know how to do it? Could someone please tell me a way to go about this
or atleast point me in the right direction?

The right direction is "away from comp.lang.c and
towards comp.lang.c++" because the latter is the newsgroup
where the experts in your chosen language congregate.
Here in comp.lang.c we discuss a different language
altogether.

When you arrive at comp.lang.c++, you'll probably
get better results if you give a clearer description of
what you are trying to do. Just what kind of a "bitmap"
are you trying to create, and what's the correspondence
between this mysterious batch of numbers and the desired
bitmap? (No, *don't* answer here; you're in the wrong
newsgroup, remember?)

Good luck!
 
M

Malcolm

Prashant said:
I have a huge problem. I have a data file which looks something like
this -:


.1 .5 .9 -1 .2 .5 ......
.2 .9 .1 .4 .3 -1 ......
.2 .4 .5 .7 .6 .2 ......
.......
.......

Now I have to create a bitmap out of this using C++ and I really dont
know how to do it? Could someone please tell me a way to go about this
or atleast point me in the right direction?
You need to use a third party library. The way the Microsoft API works, you
create a bitmap of the requisite dimensions and bit depth, and then select
it in an HDC (Handle to Device Context) and draw on it, setting each pixel
to the value you require. This is off-topic for comp.lang.c, which deals
only with the standard library.
 
P

Prashant

Esteemed sirs,

I made a mistake in writing C++ rather than C... Dont take it too hard
for I am but a novice... My problem is that I have to display the data
that I wrote (a bunch of numbers as you said) in the form of a bitmap
image... Now I know that I cannot show them as they are in the image
form.. What I would like to know is if any of you esteemed people know
how to create a bitmap image in C. I would be obliged if any of you
could help me out... I'm sorry if I wasted your precious time for it
was not what I wanted to do.

Thank you,
Prashant
 
B

Ben Pfaff

I made a mistake in writing C++ rather than C... Dont take it
too hard for I am but a novice... My problem is that I have to
display the data that I wrote (a bunch of numbers as you said)
in the form of a bitmap image...

C doesn't provide a way to display a bitmap image. Displaying
bitmaps is operating system specific, so you should ask about it
in a newsgroup specific to your OS.
Now I know that I cannot show them as they are in the image
form.. What I would like to know is if any of you esteemed
people know how to create a bitmap image in C. I would be
obliged if any of you could help me out... I'm sorry if I
wasted your precious time for it was not what I wanted to do.

Creating a bitmap image *file* can be done portably. There are
plenty of libraries that you can use to help, e.g. libpng. None
of these libraries are on-topic in this newsgroup, so you should
seek other places to talk about them.
 
M

Mike Wahler

Prashant said:
Esteemed sirs,

I made a mistake in writing C++ rather than C... Dont take it too hard
for I am but a novice... My problem is that I have to display the data
that I wrote (a bunch of numbers as you said) in the form of a bitmap
image... Now I know that I cannot show them as they are in the image
form.. What I would like to know is if any of you esteemed people know
how to create a bitmap image in C.

The format of a 'bitmap' image will depend upon
the ultimate target display device (and typically other
factors). This data could indeed be written to memory or
to a file using standard C, but nobody could do it without the
specification for the format. And of course actual rendering of
the image on a display device cannot be done with standard C, because
C doesn't presume that such a device exists. All i/o is done via
'streams of characters'.
I would be obliged if any of you
could help me out... I'm sorry if I wasted your precious time for it
was not what I wanted to do.

Try asking in a forum where your OS and platform are topical.
Or if you supply the desired format, someone might be willing to take
time to present some code.


-Mike
 
R

Richard Bos

I made a mistake in writing C++ rather than C... Dont take it too hard
for I am but a novice... My problem is that I have to display the data
that I wrote (a bunch of numbers as you said) in the form of a bitmap
image... Now I know that I cannot show them as they are in the image
form.. What I would like to know is if any of you esteemed people know
how to create a bitmap image in C.

Displaying the image on screen, and everything related to it is system-
specific, and therefore off-topic here. Writing a bitmap file, or even
creating a bitmap in memory, can be done in ISO C; the problem is
figuring out what kind of bitmap you want. Once you've figured that out
(and that, again, depends on your hardware and OS), it all just boils
down to writing the right bytes in the right place, using fwrite(),
memcpy(), or simple assignment through pointers. That done, you need to
display the image - and that is beyond ISO C, again.
You may find this useful: <http://www.wotsit.org/search.asp?s=graphics>

Richard
 

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

Members online

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,378
Latest member
BlakeLig

Latest Threads

Top