tag:blogger.com,1999:blog-7092135066960371093.post5663855130855997281..comments2024-01-07T18:31:51.524-08:00Comments on C Tutor... C Tutorial....: How to load picture in C Program.Pop's Worldhttp://www.blogger.com/profile/04964875113190825498noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7092135066960371093.post-41798291501744273432012-05-29T12:45:21.501-07:002012-05-29T12:45:21.501-07:00hello i am trying to send a bmp file through socke...hello i am trying to send a bmp file through socket this is the sender but for a reason my buffers do not other bits than 0 or 255 and my image is white ...could someone help me please <br /><br /><br /><br /><br />#include /* for type definitions */<br />#include /* for socket API function calls */<br />#include /* for address structs */<br />#include /* for sockaddr_in */<br />#include /* for printf() */<br />#include /* for atoi() */<br />#include /* for strlen() */<br />#include /* for close() */<br />#include <br />#include <br />#include <br />#include <br />#include <br />#include <br /><br />int main (int argc,char **argv)<br />{<br />int error;<br />int s;<br />int q,w,e,r;<br />unsigned char buf1 [49152];<br />unsigned char buf2 [49152];<br />unsigned char buf3 [49152];<br />unsigned char buf4 [49152];<br /><br />size_t len;<br /> FILE * fp;<br /> unsigned long cnt,im_row,im_col;<br /> unsigned char tc;<br /> unsigned int w1,w2,width,height,h1,h2,offset,bpp,j;<br /> unsigned int padd,i,l;<br /> unsigned char image[256][256][3]; <br /> unsigned char tmpim[196608];<br /><br />struct addrinfo hint, *res;<br />struct addrinfo *multi;<br /><br />memset( &hint, 0, sizeof( hint ) );<br />hint.ai_family = AF_INET6;<br />hint.ai_socktype = SOCK_DGRAM;<br />hint.ai_protocol = 0;<br /><br />error = getaddrinfo( "ff02::1", NULL, &hint, &res );<br /><br />if( error != 0 ) {<br /> perror( "getaddrinfo" );<br /> <br />}<br /><br />struct sockaddr_in6 * addr = (struct sockaddr_in6*)res->ai_addr;<br />addr->sin6_port = htons( 7890 );<br />addr->sin6_scope_id = 2; // 2 happens to be the interface ID<br />s = socket( AF_INET6, SOCK_DGRAM, 0 );<br /><br /> if ( !(fp=fopen("Anemos.bmp","rb"))) <br /> {<br /> printf("Unable to load bin file: %s...\n","Anemos.bmp");<br /> }<br /> else<br /> {<br /> cnt = 0;<br /> im_row=0;<br /> im_col=0;<br /> while (!feof(fp)) {<br /> tc = fgetc(fp) & 0x0ff;<br /> <br /> if (cnt==10) offset=tc;<br /> if (cnt==18) w1=tc;<br /> if (cnt==19) w2=tc;<br /> if (cnt==22) h1=tc;<br /> if (cnt==23) h2=tc; <br /> if (cnt==28) bpp=tc; <br /> if ((cnt==30)&&(tc>0)) printf("ERROR!! Cannot Handle BMP files with Compression!!!\n");<br /> if (cnt==53) break;<br /> <br /> cnt++;<br /> }<br /> }<br /><br /> width = w1+w2*256;<br /> height = h1+h2*256; <br /> <br /> int BMPRES_X = width;<br /> int BMPRES_Y = height;<br /> <br /> padd = 0; <br /> printf("W:%d, H:%d Image Data Starts at:%d with %d bits/pixel \n",width,height,offset,bpp);<br /> <br /> for ( im_row=0;im_rowai_addr, res->ai_addrlen ) !=49152) {<br /> printf( "Error sending buf1\n" );<br /> printf(" afou dn stalthike o protos buffer tote diakoptete i apostoli\n");<br /> exit(1);<br /> } else printf("Buf1 OK! \n",buf1); <br /> <br /><br /><br />if( sendto( s, buf2, 49152, 0, res->ai_addr, res->ai_addrlen ) !=49152) {<br /> printf( "Error sending buf2\n" );<br /> } else printf("Buf2 OK!\n");<br /> <br /><br />if( sendto( s, buf3, 49152, 0, res->ai_addr, res->ai_addrlen ) !=49152) {<br /> printf( "Error sending buf3\n" );<br /> } else printf("Buf3 OK!\n"); <br /><br />if( sendto( s, buf4, 49152, 0, res->ai_addr, res->ai_addrlen ) !=49152) {<br /> printf( "Error sending buf4\n" );<br /> }else printf("Buf4 OK!\n");<br /><br />exit(1);<br />}ΠΑΣΠ -ΤΕΣΥΔhttps://www.blogger.com/profile/15362871938779012591noreply@blogger.comtag:blogger.com,1999:blog-7092135066960371093.post-25213936818620997502012-05-29T12:40:30.531-07:002012-05-29T12:40:30.531-07:00This comment has been removed by the author.ΠΑΣΠ -ΤΕΣΥΔhttps://www.blogger.com/profile/15362871938779012591noreply@blogger.com