Forum Discussion
Altera_Forum
Honored Contributor
20 years agoHow to store a BMP file to nios board from a PC
Hi
I am using the Apex20kE device I got a problem to load a bmp file to the Nios development board. Here is my code # include <stdio.h># include <nios.h> # define K 12960 main(void) { FILE *fp; char p[K]; int i; fp=fopen("d:\\picture.bmp","rb" ) ; if (fp==NULL) { printf("Can not open file.\n"); exit(1); } fgets(p,K,fp); fclose(fp); for(i=0;i<K;i++) printf("%8x,",p[i]); return 0; } Well ,it doest work I don't want to write the image pixel by pixel Is there anyone who can help me?2 Replies
- Altera_Forum
Honored Contributor
I'm assuming K is the size of the file you want to read so you could try:
fread(p, 1, K, fp); which reads K "items" of size 1 byte. fread returns the number of items read so you can test whether it worked like this: numRead =fread(p,1,K,fp); if (numRead != K) printf("read only %d of %d\n", numRead, K); The reason you cannot use fgets is that that function stops when it encounters a newline in the data. By the way, you can look at the Windows structures BITMAPFILEHEADER and BITMAPINFO to find a way of properly parsing out a bitmap. Andrew - Altera_Forum
Honored Contributor
I am not clear about " Apex20kE" device.
but your program has no Filesystem support.may that be the reason? thanks