bmp - How to generate an image using C code -


the function below serves html when called,

void generatehtml (int socket) {    char* message;     // sends http response header     message = "http/1.0 200 ok\r\n"                 "content-type: text/html\r\n"                 "\r\n";    printf ("about send=> %s\n", message);    write (socket, message, strlen (message));     message = "<html><body><p>hello world.</p></body></html>\n";    printf ("about send=> %s\n", message);    write (socket, message, strlen (message));    } 

my output on web browser simple hello world message. however, want change display bitmap image instead. let's use 1x1 red pixel our bmp.

i've modified function far by:

void generatehtml (int socket) {    char* message;     // sends http response header     message = "http/1.0 200 ok\r\n"                 "content-type: image/bmp\r\n"                 "content-length: ???wtf???\r\n";    printf ("about send=> %s\n", message);    write (socket, message, strlen (message));     message = "bmf8\n";    printf ("about send=> %s\n", message);    write (socket, message, strlen (message));        message = " "; //bmp file data goes here.    printf ("about send=> %s\n", message);    write (socket, message, strlen (message));    } 

quoting dan's answer, data in hex looks like:

0000000: 424d 3a00 0000 0000 0000 3600 0000 2800  bm:.......6...(. 0000010: 0000 0100 0000 0100 0000 0100 1800 0000  ................ 0000020: 0000 0400 0000 130b 0000 130b 0000 0000  ................ 0000030: 0000 0000 0000 0000 0000                 .......... 

however, cannot place inside quotation marks. how this?

this xxd dump of 1x1 black windows bmp image:

0000000: 424d 3a00 0000 0000 0000 3600 0000 2800  bm:.......6...(. 0000010: 0000 0100 0000 0100 0000 0100 1800 0000  ................ 0000020: 0000 0400 0000 130b 0000 130b 0000 0000  ................ 0000030: 0000 0000 0000 0000 0000                 .......... 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -