loading an image in a c program

M

Maryam

I am looking for an include or header file to transfer an image(*.bmp)
in to my c program.is there any tool for this purpose?
Thank you.
Maryam
 
M

Malcolm

Maryam said:
I am looking for an include or header file to transfer an image
(*.bmp)
in to my c program.is there any tool for this purpose?
Let's say we have an image file in an arbitrary format. The way to load it
is to write a function

/*
fname - bmp file to open.
width - return pointer for image width.
height - return pointer for image height.
returns - malloced pointer to 24 bit rgb data, NULL on fail.
*/
unsigned char *loadimagebmp(char *fname, int *width, int *height)

The problem comes when the image format, like JPEG, is so complex that you
can't reasonably be expected to decipher it yourself. Here you have to use
non-standard library functions, which may ship with the compiler or you may
cut and paste from the web.

Often you want to embed images in an executable. This is only practical
using some sort of automated tool. Such tools are included in MSVC++, but
are not topical here.
 
D

Dan Henry

I am looking for an include or header file to transfer an image(*.bmp)
in to my c program.is there any tool for this purpose?

If I am understanding your requirements correctly, 010 Editor (an
inexpensive Windows application) can do this interactively or
programmatically.

See http://www.sweetscape.com/010editor/

For example, the tool exported a .bmp file exported to a C source
file:

//------------------------------------------------------------
//----------- Created with 010 Editor -----------
//------ www.sweetscape.com/010editor/ ------
//
// File : C:\WINNT\Blue Lace 16.bmp
// Address : 0 (0x0)
// Size : 1272 (0x4F8)
//------------------------------------------------------------
unsigned char hexData[1272] = {
0x42, 0x4D, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00,
0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x0E,
0x00, 0x00, 0xC3, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00,
0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0xC0, 0xC0,
0xC0, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF,
0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x44, 0x44,
0x44, 0x4C, 0x44, 0x44, 0x44, 0x44, 0xC4, 0xC4,
0x44, 0x44, 0x44, 0x44, 0xC4, 0xC4, 0x44, 0x44,
/* ... */
0x44, 0x44, 0x44, 0x44, 0xC4, 0x4C, 0x44, 0x44,
0x44, 0x44, 0xCC, 0xC4, 0x44, 0x44, 0x00, 0x00
};
 
C

CBFalconer

Dan said:
If I am understanding your requirements correctly, 010 Editor (an
inexpensive Windows application) can do this interactively or
programmatically.
.... snip ...
0x42, 0x4D, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x28, 0x00,

If that is what he wants he can do it with debug, which AFAIK
still comes with every Windoze installation, and a little
massaging in any text editor. drdebug, which is available with
drdos, is a little better.
 

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,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top