Bonjour j'ai réussis à créer mes bitmap mais j'ai un petit problème avec la façon dont ils sont générés.
Je vous explique la façon dont est censé fonctionner mon programme:
Je passe en paramètre 2 images contenant des caractères la premiere en 2 lignes 1 2 3 et 4 5 6 et la 2e A et G aux position 1 et 6.
Je génère ensuite un premier bitmap aléatoirement qui doit avoir cette forme la:
11 01 10 01 00 10 ...
00 10 10 01 11 01 ...
L'image doit faire 472*472 soit 236 matrice 2*2
Ensuite je génère un 2e BMP de la façon suivante:
-Je recopie la première
-Je parcours les pixels de mes 2 images en paramètres
-Sur les pixels des lignes pairs si le pixel est noir j'inverse la matrice de même rang(chaque pixel de l'image source correspond a une matrice de l'image générés)
-Sur les lignes impair je fait de même avec la 2e images.

Je devrait donc me retrouver avec une 2e image sur laquelle je doit pouvoir voir
1 2 3
4 5 6
avec un AG au même niveau que la 1 et le 6 mais je me retrouve avec
3 1 2
4 5 6
avec le G au niveau du 1 et le A coupé en 2 entre le 6 et le 4.

Je vous montre mon code source:
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
class cases
{
	protected:
		bool coul;
	public:
		cases();
		cases(bool);
		bool getinfo();
		void setinfo(bool);
		cases& operator=(cases&);
 
		~cases();
 
};
 
class matrice
{
	protected:
		static long flag;
		cases ***tab;
		int nb;
	public:
		matrice();
		matrice(bool);
		matrice(matrice&,int,bool);
		matrice(int);
		matrice toggle();
		void shuffle();
		bool getinfo(int,int);
		matrice& operator=(matrice&);
		void write(FILE *);
		void writeh(FILE*);
		void writed(FILE*);
		void writem(FILE*);
 
		~matrice();
 
 
 
};
 
class filtre
{
	protected:
 
		int nb;
	public:
		filtre(int);
		void write(int);
		void Create_Save_BMP();
		matrice getmat(int,int);
		~filtre();
		matrice ***tab;
};
 
class content
{
	protected:
		int nb;
		matrice ***tab;
		FILE *img;
	public:
		content(filtre&);
		void Create_Save_BMP();
		void write();
		~content();
 
 
};
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
cases::cases()
{
	coul= NULL;
 
}
cases::cases(bool c)
{
	coul= c;
 
}
bool cases::getinfo()
{
 
	return coul;
}
void cases::setinfo(bool c)
{
	coul=c;
}
 
cases::~cases()
{
 
}
cases& cases::operator=(cases& source)
{
	coul=source.coul;
	return *this;
 
}
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
 
long matrice::flag=0;
 
 
matrice::matrice(matrice& m1,int l,bool p)
{
	if(p)
	{
		nb=l;
		flag++;
		tab= new cases**[l];
 
		for(int i=0;i<l;i++)
		{
			tab[i]=new cases*[l];
			for (int j=0;j<l;j++)
			{
 
				if(m1.getinfo(i,j)) tab[i][j] = new cases(false); else tab[i][j]= new cases(true);
 
			}
		}
	}
	else
	{
			nb=l;
		flag++;
		tab= new cases**[l];
 
		for(int i=0;i<l;i++)
		{
			tab[i]=new cases*[l];
			for (int j=0;j<l;j++)
			{
 
				if(m1.getinfo(i,j)) tab[i][j] = new cases(true); else tab[i][j]= new cases(false);
 
			}
		}
 
	}
}
matrice::matrice()
{
	nb=2;
	tab= new cases**[2];
 
    for(int i=0;i<2;i++)
    {
        tab[i]=new cases*[2];
        for (int j=0;j<2;j++)
        {
			tab[i][j]=NULL;
 
		}
	}
 
	if(flag==0)
	{
		srand((time(NULL)));//initialisation du random seulement pour la création de la première instance de matrice
		matrice::flag +=1;
	}	
 
	int j=1+(int) (6*rand()/(RAND_MAX+1.0));
	switch (j)
	{
 
		case 1:
			tab[0][0]=new cases(true);
			tab[0][1]=new cases(true);
			tab[1][0]=new cases(false);
			tab[1][1]=new cases(false);
            break;
        case 2:
            tab[0][0]=new cases(true);
			tab[0][1]=new cases(false);
			tab[1][0]=new cases(true);
			tab[1][1]=new cases(false);
            break;
        case 3:
            tab[0][0]=new cases(true);
			tab[0][1]=new cases(false);
			tab[1][0]=new cases(false);
			tab[1][1]=new cases(true);
            break;
        case 4:
            tab[0][0]=new cases(false);
			tab[0][1]=new cases(true);
			tab[1][0]=new cases(true);
			tab[1][1]=new cases(false);
            break;
		case 5:
            tab[0][0]=new cases(false);
			tab[0][1]=new cases(true);
			tab[1][0]=new cases(false);
			tab[1][1]=new cases(true);
            break;
		case 6:
            tab[0][0]=new cases(false);
			tab[0][1]=new cases(false);
			tab[1][0]=new cases(true);
			tab[1][1]=new cases(true);                        
 
	}	
}
 
matrice::matrice(int n)
{
	if(flag==0)
	{
	srand((time(NULL)));
	flag+=1;
	}
	nb=n;
	tab= new cases**[nb];
 
 
    for(int i=0;i<nb;i++)
    {
        tab[i]=new cases*[nb];
        for (int j=0;j<nb;j++)
        {
 
			tab[i][j]=new cases(true);
 
 
		}
	}
 
}
 
matrice::matrice(bool flag)
{
	if(flag)
	{
		tab= new cases**[2];
 
		for(int i=0;i<2;i++)
		{
			tab[i]=new cases*[2];
			for (int j=0;j<2;j++)
			{
				tab[i][j]=NULL;
 
			}
		}
	}
}
 
 
 
 
 
 
 
 
matrice::~matrice()
{
 
    for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			delete(tab[i][j]);
		}
		delete(tab[i]);
    }
	delete(tab);
}
 
 
bool matrice::getinfo(int i,int j)
{
	bool a=(tab[i][j])->getinfo();
	return a;
}
 
 
 
void matrice::write(FILE *f3)
{
 
	remove("./filtre33.txt");
 
	for(int i=0;i<nb;i++)
	{
		for(int j=0;j<nb;j++)
		{
			if(getinfo(i,j))
			{
				fprintf(f3, "1");
			}
			else fprintf(f3, "0");
		}
 
 
 
	}
 
 
	matrice::flag=matrice::flag+1;
 
}
 
void matrice::writed(FILE *f3)
{
 
	for(int i=0;i<nb;i++)
	{
 
			if(getinfo(i,1))
			{
				fprintf(f3, "1");
			}
			else fprintf(f3, "0");
 
 
 
 
	}
 
 
 
 
}
 
 
void matrice::writeh(FILE *f3)
{
 
	for(int i=0;i<nb;i++)
	{
 
			if(getinfo(i,0))
			{
				fprintf(f3, "1");
			}
			else fprintf(f3, "0");
 
 
 
 
	}
 
 
	matrice::flag=matrice::flag+1;
 
}
 
 
 
void matrice::writem(FILE *f3)
{
 
	for(int i=0;i<nb;i++)
	{
 
			if(getinfo(i,2))
			{
				fprintf(f3, "1");
			}
			else fprintf(f3, "0");
 
 
 
 
	}
 
 
	matrice::flag=matrice::flag+1;
 
}
 
 
 
 
matrice& matrice::operator=(matrice& source)//non fonctionnel
{
 
    for (int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			delete tab[i][j];
		}
		delete tab[i];
	}
	delete tab;
 
	tab= new cases**[2];
 
    for(int k=0;k<2;k++)
    {
        tab[k]=new cases*[2];
        for (int l=0;l<2;l++)
        {
			if(source.getinfo(k,l))tab[k][l]=new cases(true); else tab[k][l]=new cases(false);
 
		}
	}
	return (*this);
 
 
}
 
 
void matrice::shuffle()
{
	if(flag==0)
	{
	srand((time(NULL)));
	flag+=1;
	}
	int m=1+(int) (2*rand()/(RAND_MAX+1.0))-1;
	m+=4;
	int i=0;
	while(i<m)
	{
		int k=1+(int) (3*rand()/(RAND_MAX+1.0))-1;
		int j=1+(int) (3*rand()/(RAND_MAX+1.0))-1;
		if((tab[k][j]->getinfo()))
		{	delete(tab[k][j]);
			tab[k][j]=new cases(false);
			i++;
		}
 
	}
}
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
filtre::~filtre()
{
	for(int i=0;i<256/nb;i++)
	{
		for(int j=0;j<256/nb;j++)
		{
			delete(tab[i][j]);
		}
		delete(tab[i]);
    }
	delete(tab);
 
}
 
 
 
filtre::filtre(int n)
{
 
	if(n==2)
	{
		tab= new matrice**[236];
 
		for(int i=0;i<236;i++)
		{
			tab[i]=new matrice*[236];
			for (int j=0;j<236;j++)
			{
				if(i%2==0)
				{
					tab[i][j]= new matrice;
				}
				else
				{
					tab[i][j]= new matrice(*tab[i-1][j],n,true);
				}
 
			}
		}
	}
	else
	{
		tab= new matrice**[157];
 
		for(int i=0;i<157;i++)
		{
			tab[i]=new matrice*[157];
			for (int j=0;j<157;j++)
			{
				if(i%2==0)
				{
					tab[i][j]= new matrice(3);
					tab[i][j]->shuffle();
				}
				else
				{
					tab[i][j]= new matrice(*tab[i-1][j],n,true);
				}
 
			}
		}	
 
	}
}
 
 
 
 
void filtre::write(int n)
{
	FILE *f3=NULL;
	f3=fopen("./filtre1.txt","at+");
 
	if (n==2)
	{
		remove("./filtre1.txt");
		for(int i=0;i<236;i++)
		{
			for(int j=0;j<236;j++)
			{
				tab[i][j]->writeh(f3);//ecrit les lignes du haut des matrice (a1n)
			}
 
			for(j=0;j<236;j++)
			{
				tab[i][j]->writed(f3);//ecrit les lignes du bas des matrice (a2n)
			}
 
 
		}
	}
		if (n==3)
	{
		remove("./filtre1.txt");
		for(int i=0;i<157;i++)
		{
			for(int j=0;j<157;j++)
			{
				tab[i][j]->writeh(f3);//ecrit les lignes du haut des matrice (a1n)
			}
 
 
			for(j=0;j<157;j++)
			{
				tab[i][j]->writed(f3);//ecrit les lignes du millieu des matrice (a2n)
			}
 
 
 
			for(j=0;j<157;j++)
			{
				tab[i][j]->writem(f3);//ecrit les lignes du haut des matrice (a3n)
			}
 
 
			fclose(f3);
		}
	}
 
}
 
 
 
void filtre::Create_Save_BMP()
{
 
	std::ifstream fichier("./filtre1.txt", std::ios::in);
 
	 char caractere;
	int c=0,i=0;
    int x=0;
    int iWidth = 472;
    int iHeight = 472;
    HANDLE file;
    BITMAPFILEHEADER fileHeader;
    BITMAPINFOHEADER fileInfo;
    RGBTRIPLE image;
    DWORD write = 0;
 
    file = CreateFile("F1.bmp",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    fileHeader.bfType = 19778;
    fileHeader.bfSize = sizeof(fileHeader.bfOffBits) + sizeof(RGBTRIPLE);
    fileHeader.bfReserved1 = 0;
    fileHeader.bfReserved2 = 0;
    fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
 
    fileInfo.biSize = sizeof(BITMAPINFOHEADER);
    fileInfo.biWidth = iWidth;
    fileInfo.biHeight = iHeight;
    fileInfo.biPlanes = 1;
    fileInfo.biBitCount = 24;
    fileInfo.biCompression = BI_RGB;
    fileInfo.biSizeImage = 0;
    fileInfo.biXPelsPerMeter = 0;
    fileInfo.biYPelsPerMeter = 0;
    fileInfo.biClrImportant = 0;
    fileInfo.biClrUsed = 0;
 
    WriteFile(file,&fileHeader,sizeof(fileHeader),&write,NULL);
    WriteFile(file,&fileInfo,sizeof(fileInfo),&write,NULL);
 
 
    while(i < (iWidth*iHeight))
    {
		fichier.get(caractere);
		int j=i;
        if(caractere=='0')
           {
			x=254;
			}
        else 
		{
			x=4;
		}
        image.rgbtBlue = x-1;
        image.rgbtGreen = x-1;
        image.rgbtRed = x-1;
        WriteFile(file, &image, sizeof(RGBTRIPLE), &write, NULL);
 
		i++;
 
 
    }
    CloseHandle(file);
	fichier.close();
 
}
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
content::content(filtre& m)
{	FILE *f1=NULL,*f2=NULL,*f3=NULL;
		f1=fopen("abc.txt","w+");
		f2=fopen("./ag.bmp","r+");
		f3=fopen("./ag.txt","w+");
	img=fopen("./chiffre1.bmp","r+");
	int abc[241][241],ga[241][241];
	int a=0,j=0,k=0;
	int caractereActuel = 0,c2=0;
	tab=new matrice**[241];
 
 
    if (img!=NULL)
    {
			caractereActuel = fgetc(img); 
 
 
			while (caractereActuel != EOF) 
			{
				a++;
				if(a>58)
				{
 
					abc[j][k]=caractereActuel;
					if(caractereActuel>128) caractereActuel=1; else caractereActuel=0;
 
					fprintf(f1, "%d", caractereActuel);
					k++;
					if(k==236)
					{
						j+=1;
						k=0;
					}
 
				}
				caractereActuel = fgetc(img);
			}
 
 
    }
	a=0;
	j=0;
	k=0;
 
	if (f2!=NULL)
    {
			c2 = fgetc(f2); 
 
 
			while (c2 != EOF) 
			{
				a++;
				if(a>58)
				{
 
					ga[j][k]=c2;
					if(c2>128) c2=1; else c2=0;
 
					fprintf(f3, "%d", c2);
					k++;
					if(k==236)
					{
						j+=1;
						k=0;
					}
 
				}
				c2 = fgetc(f2);
			}
 
 
    }
 
 
 
	for(int i=0;i<236;i++)
	{
		tab[i]=new matrice*[236];
		for(int j=0;j<=235;j++)
		{
			if((abc[i][j]>128)&&(i%2==0))
			{
			tab[i][j]=new matrice(*m.tab[i][j],2,false);
			}
				else if((ga[i][j]>128)&&(i%2!=0))
			{
				tab[i][j]=new matrice(*m.tab[i][j],2,false);
			}
			else
			{
				tab[i][j]=new matrice(*m.tab[i][j],2,true);
			}
		}
	}
	fclose(f1);
	fclose(f2);
	fclose(f3);
 
}
 
 
 
void content::write()
{
		//remove("./filtre1.txt");
		FILE *f3=NULL;
		f3=fopen("./filtrecontent.txt","at+");
		for(int i=0;i<236;i++)
		{
			for(int j=0;j<236;j++)
			{
				tab[i][j]->writeh(f3);//ecrit les lignes du haut des matrice (a1n)
			}
 
 
 
			for(j=0;j<236;j++)
			{
				tab[i][j]->writed(f3);//ecrit les lignes du bas des matrice (a2n)
			}
 
 
 
		}
		fclose(f3);
 
 
 
 
 
 
 
 
 
 
}
content::~content()
{
	fclose(img);
 
}
 
 
 
void content::Create_Save_BMP()
{
 
 
    std::ifstream fichier("./filtrecontent.txt", std::ios::in);
 
	 char caractere;
	int c=0,i=0;
    int x=0;
    int iWidth = 472;
    int iHeight = 472;
    HANDLE file;
    BITMAPFILEHEADER fileHeader;
    BITMAPINFOHEADER fileInfo;
    RGBTRIPLE image;
    DWORD write = 0;
 
    file = CreateFile("F2.bmp",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    fileHeader.bfType = 19778;
    fileHeader.bfSize = sizeof(fileHeader.bfOffBits) + sizeof(RGBTRIPLE);
    fileHeader.bfReserved1 = 0;
    fileHeader.bfReserved2 = 0;
    fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
 
    fileInfo.biSize = sizeof(BITMAPINFOHEADER);
    fileInfo.biWidth = iWidth;
    fileInfo.biHeight = iHeight;
    fileInfo.biPlanes = 1;
    fileInfo.biBitCount = 24;
    fileInfo.biCompression = BI_RGB;
    fileInfo.biSizeImage = 0;
    fileInfo.biXPelsPerMeter = 0;
    fileInfo.biYPelsPerMeter = 0;
    fileInfo.biClrImportant = 0;
    fileInfo.biClrUsed = 0;
 
    WriteFile(file,&fileHeader,sizeof(fileHeader),&write,NULL);
    WriteFile(file,&fileInfo,sizeof(fileInfo),&write,NULL);
 
 
    while(i < (iWidth*iHeight))
    {
		fichier.get(caractere);
		int j=i;
        if(caractere=='0')
           {
			x=254;
			}
        else 
		{
			x=4;
		}
        image.rgbtBlue = x-1;
        image.rgbtGreen = x-1;
        image.rgbtRed = x-1;
        WriteFile(file, &image, sizeof(RGBTRIPLE), &write, NULL);
 
		i++;
 
 
    }
    CloseHandle(file);
	fichier.close();
 
 
}
Voici les images utilisées



Et les BMP générés:






Merci bien de votre aide.