Bonjour,

je manipule des tableaux des données, et j'essaie de les sauvegarder sous forme d'images bmp.
J'ai donc fait comme dit là bas : http://www.siggraph.org/education/ma...ag/bmpfile.htm,

mais même en n'écrivant que des zéros dans mon image, je n'arrive pas à l'ouvrir avec paint ensuite...

Je n'arrive pas à savoir si mon pb vient de ma méconnaissance de la librairie standard du C (fwrite et toute la clique) ou d'une mauvaise écriture de données...

Pourriez vous jeter un oeil svp?

je n'y arrive vraiment pas...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
 
// structure encapsulant le Header BMP
typedef struct {
	char id[2];
	long filesize;
	int reserved[2];
	long headersize;
	long infoSize;
	long width;
	long depth;
	short biPlanes;
	short bits;
	long biCompression;
	long biSizeImage;
	long biXPelsPerMeter;
	long biYPelsPerMeter;
	long biClrUsed;
	long biClrImportant;
} BMPHEAD;
 
 
 
 
void display (float* alt, int pixels)
{
             // ouverture du fichier de sortie
	FILE* out = fopen("img.bmp", "wb") ;
	if (out == NULL) {
		cout << "error : no file !" << endl ;
		return ;
	}
             // REMPLISSAGE DU HEADER
	BMPHEAD bh ;
	memset ((char *) &bh, 0, sizeof(BMPHEAD)) ; /* sets everything to 0 */
	memcpy (bh.id, "BM", 2) ;
	bh.filesize ; // =   calculated size of your file (see below)
	//bh.reserved[0] = 0 ; bh.reserved[1] = 0 ;
	bh.headersize  = 54L  ; // (for 24 bit images)
	bh.infoSize  =  0x28L ; // (for 24 bit images)
	bh.width     = (long) pixels ; // size in pixels of your image
	bh.depth     = (long) pixels ; // size in pixels of your image
	bh.biPlanes  =  1 ; // (for 24 bit images)
	bh.bits      = 24 ; // (for 24 bit images)
	bh.biCompression = 0L ;  // (no compression)
	int bytesPerLine;
 
	bytesPerLine = bh.width * 3;  /* (for 24 bit images) */
	/* round up to a d word boundary */
	if (bytesPerLine & 0x0003) 
	{
		bytesPerLine |= 0x0003;
		++bytesPerLine;
	}
	bh.filesize=bh.headersize+(long)bytesPerLine*bh.depth;
	fwrite(&bh, 1, sizeof (bh), out);
	// end header
 
	char *linebuf;
 
	linebuf = (char *) calloc(1, bytesPerLine);
	if (linebuf == NULL) {
		printf ("Error allocating memory\n");
		exit (1);   
	}
	for (int line = pixels-1 ; line >= 0 ; --line)
	{
		for (int j = 0 ; j < pixels ; ++j)
		{
                          // ICI , JE N'ECRIS QUE DES ZEROS, EN M'ATTENDANT
                          // A UN CARRE NOIR EN SORTIE
			int midx = line*pixels + j ;
			if (alt[midx] == -10.f) {
				linebuf[3*j] = (char) 0 ;
				linebuf[3*j+1] = (char) 0 ;
				linebuf[3*j+2] = (char) 0 ;
			}
			else {
				linebuf[3*j] = (char) 0 ; 				linebuf[3*j+1] = (char) 0 ; 				linebuf[3*j+2] = (char) 0 ;			
}
		}
		fwrite(linebuf, 1, bytesPerLine, out);
	}
	free(linebuf) ;
	fclose (out) ;
}