質問編集履歴
1
問題点を詳しくさせていただきました。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
拡大・縮小
|
|
1
|
+
拡大・縮小を行うことはできるようになったのですが、8bitのBMPファイルで3.33倍,0.33倍を行うことができません。サポートされていないと出ます。BMPファイル24bit、32bitだと問題なく行えます。
|
|
2
2
|
```c言語
|
|
3
3
|
#include<stdio.h>
|
|
4
4
|
#include<math.h>
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
unsigned long bfSize; //ファイルサイズ (byte)
|
|
14
14
|
unsigned short bfReserved1; //予約領域
|
|
15
15
|
unsigned short bfReserved2; //予約領域
|
|
16
|
-
unsigned long bfOffBits; //
|
|
16
|
+
unsigned long bfOffBits; //ファイル先頭から画像データまでのオフセット (byte)
|
|
17
17
|
} BITMAPFILEHEADER;
|
|
18
18
|
#pragma pack(pop)
|
|
19
19
|
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
{
|
|
45
45
|
BITMAPFILEHEADER BitMapFileHeader; //BMPのファイルヘッダー
|
|
46
46
|
BITMAPINFOHEADER BitMapInfoHeader; //BMPの情報ヘッダー
|
|
47
|
-
RGBQUAD BitMapColor; //カラーパレット
|
|
47
|
+
RGBQUAD BitMapColor[1000]; //カラーパレット
|
|
48
48
|
BYTE *pImg, *pChangeImg;
|
|
49
|
-
int i, j, k,l, m, iSize, sp1=0, sp2=0;
|
|
49
|
+
int i, j, k,l, m, iSize, sp1=0, sp2=0, iColor;
|
|
50
|
-
|
|
50
|
+
int lWidth, lHeight;
|
|
51
51
|
double dMult;
|
|
52
|
-
double dWidthSp, dHeightSp;
|
|
52
|
+
double dWidthSp, dHeightSp,dk;
|
|
53
53
|
int iWidthSp, iHeightSp;
|
|
54
54
|
FILE *fp;
|
|
55
55
|
|
|
@@ -82,17 +82,15 @@
|
|
|
82
82
|
switch(BitMapInfoHeader.biBitCount)
|
|
83
83
|
{
|
|
84
84
|
case 8:
|
|
85
|
+
iColor = (BitMapFileHeader.bfOffBits-54)/4;
|
|
85
|
-
fread(&BitMapColor,sizeof(RGBQUAD),
|
|
86
|
+
fread(&BitMapColor,sizeof(RGBQUAD),iColor ,fp);
|
|
86
|
-
iSize =
|
|
87
|
+
iSize = BitMapInfoHeader.biWidth * BitMapInfoHeader.biHeight;
|
|
87
|
-
printf("%d\n",BitMapInfoHeader.biBitCount);
|
|
88
88
|
break;
|
|
89
89
|
case 24:
|
|
90
90
|
iSize = BitMapFileHeader.bfSize - ( 14 + 40 );
|
|
91
|
-
printf("%d\n",BitMapInfoHeader.biBitCount);
|
|
92
91
|
break;
|
|
93
92
|
case 32:
|
|
94
93
|
iSize = BitMapFileHeader.bfSize - ( 14 + 40 );
|
|
95
|
-
printf("%d\n",BitMapInfoHeader.biBitCount);
|
|
96
94
|
break;
|
|
97
95
|
default:
|
|
98
96
|
printf("失敗しました");
|
|
@@ -117,31 +115,25 @@
|
|
|
117
115
|
|
|
118
116
|
iSize = iSize * pow(dMult,2);
|
|
119
117
|
|
|
118
|
+
printf("%d\n",iSize);
|
|
119
|
+
printf("%d\n",BitMapFileHeader.bfSize);
|
|
120
|
+
printf("%d\n",BitMapInfoHeader.biWidth);
|
|
121
|
+
printf("%d\n",BitMapInfoHeader.biHeight);
|
|
122
|
+
printf("%d\n\n\n",BitMapInfoHeader.biSizeImage);
|
|
123
|
+
|
|
120
124
|
lWidth = BitMapInfoHeader.biWidth;
|
|
121
125
|
lHeight = BitMapInfoHeader.biHeight;
|
|
122
126
|
|
|
123
|
-
BitMapFileHeader.bfSize =
|
|
127
|
+
BitMapFileHeader.bfSize = iSize + BitMapFileHeader.bfOffBits;
|
|
124
128
|
BitMapInfoHeader.biWidth = BitMapInfoHeader.biWidth * dMult;
|
|
125
129
|
BitMapInfoHeader.biHeight = BitMapInfoHeader.biHeight * dMult;
|
|
126
130
|
BitMapInfoHeader.biSizeImage = BitMapInfoHeader.biSizeImage * pow(dMult,2);
|
|
127
131
|
|
|
132
|
+
printf("%d\n",BitMapFileHeader.bfSize);
|
|
128
|
-
|
|
133
|
+
printf("%d\n",BitMapInfoHeader.biWidth);
|
|
129
|
-
|
|
134
|
+
printf("%d\n",BitMapInfoHeader.biHeight);
|
|
135
|
+
printf("%d\n",BitMapInfoHeader.biSizeImage);
|
|
130
136
|
|
|
131
|
-
//拡大、縮小 の倍率
|
|
132
|
-
|
|
133
|
-
printf("倍率 %lf\n",dMult);
|
|
134
|
-
printf("width %d\n",lWidth);
|
|
135
|
-
printf("height %d\n",lHeight);
|
|
136
|
-
printf("Size %d\n",iSize);
|
|
137
|
-
|
|
138
|
-
printf("倍率 %lf\n",dMult);
|
|
139
|
-
printf("width %d\n",BitMapInfoHeader.biWidth);
|
|
140
|
-
printf("height %d\n",BitMapInfoHeader.biHeight);
|
|
141
|
-
printf("Size %d\n",BitMapFileHeader.bfSize);
|
|
142
|
-
printf("Size %d\n",BitMapInfoHeader.biSizeImage);
|
|
143
|
-
|
|
144
|
-
|
|
145
137
|
//ファイルヘッダーを書き込む
|
|
146
138
|
fwrite(&BitMapFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
|
|
147
139
|
//情報ヘッダーを書き込む
|
|
@@ -155,41 +147,43 @@
|
|
|
155
147
|
{
|
|
156
148
|
//8bitのときを書き込む
|
|
157
149
|
case 8:
|
|
158
|
-
fwrite(&BitMapColor,sizeof(RGBQUAD),
|
|
150
|
+
fwrite(&BitMapColor,sizeof(RGBQUAD),iColor,fp);
|
|
159
151
|
|
|
160
152
|
for(i=0; i < BitMapInfoHeader.biHeight; i++)
|
|
161
153
|
{
|
|
162
154
|
for(j=0; j<BitMapInfoHeader.biWidth; j++)
|
|
163
155
|
{
|
|
164
|
-
|
|
165
156
|
dHeightSp = 1/dMult*i;
|
|
166
157
|
dWidthSp = 1/dMult*j;
|
|
167
158
|
|
|
168
|
-
iHeightSp = (int)
|
|
159
|
+
iHeightSp = (int)dHeightSp;
|
|
169
|
-
iWidthSp = (int)
|
|
160
|
+
iWidthSp = (int)dWidthSp;
|
|
170
161
|
|
|
171
|
-
sp2 = iWidthSp + ( iHeightSp * lWidth
|
|
162
|
+
sp2 = iWidthSp + ( iHeightSp * lWidth);
|
|
172
163
|
|
|
173
164
|
*(pChangeImg+sp1) = *(pImg+sp2);
|
|
174
165
|
sp1++;
|
|
175
166
|
}
|
|
176
|
-
|
|
177
|
-
printf("j %d\nheight %d\n",i,lHeight);
|
|
178
|
-
printf("sp1 %d\nsp2 %d\n",sp1,sp2);
|
|
179
167
|
}
|
|
180
|
-
|
|
181
|
-
printf("完了");
|
|
182
168
|
break;
|
|
183
169
|
|
|
184
170
|
//24bitのときを書き込む
|
|
185
171
|
case 24:
|
|
186
|
-
for(
|
|
172
|
+
for(i=0; i<BitMapInfoHeader.biHeight; i++)
|
|
187
173
|
{
|
|
188
|
-
for(
|
|
174
|
+
for(j=0; j<BitMapInfoHeader.biWidth; j++)
|
|
189
175
|
{
|
|
176
|
+
dHeightSp = 1/dMult*i;
|
|
177
|
+
dWidthSp = 1/dMult*j;
|
|
178
|
+
|
|
179
|
+
iHeightSp = (int)dHeightSp;
|
|
180
|
+
iWidthSp = (int)dWidthSp;
|
|
181
|
+
|
|
182
|
+
sp2 = ((iWidthSp * 3) + (iHeightSp * lWidth * 3)) ;
|
|
183
|
+
|
|
190
184
|
for(k=0; k<3; k++)
|
|
191
185
|
{
|
|
192
|
-
*(pChangeImg+
|
|
186
|
+
*(pChangeImg+sp1) = *(pImg+sp2);
|
|
193
187
|
sp1++;
|
|
194
188
|
sp2++;
|
|
195
189
|
}
|
|
@@ -199,31 +193,34 @@
|
|
|
199
193
|
|
|
200
194
|
//32bitのときを書き込む
|
|
201
195
|
case 32:
|
|
202
|
-
for(i=0; i<
|
|
196
|
+
for(i=0; i<BitMapInfoHeader.biHeight; i++)
|
|
203
197
|
{
|
|
204
|
-
for(j=0; j<
|
|
198
|
+
for(j=0; j<BitMapInfoHeader.biWidth; j++)
|
|
205
199
|
{
|
|
200
|
+
dHeightSp = 1/dMult*i;
|
|
201
|
+
dWidthSp = 1/dMult*j;
|
|
202
|
+
|
|
203
|
+
iHeightSp = (int)dHeightSp;
|
|
204
|
+
iWidthSp = (int)dWidthSp;
|
|
205
|
+
|
|
206
|
+
sp2 = ((iWidthSp * 4) + (iHeightSp * lWidth * 4)) ;
|
|
207
|
+
|
|
206
208
|
for(k=0; k<4; k++)
|
|
207
209
|
{
|
|
208
|
-
*(pChangeImg+
|
|
210
|
+
*(pChangeImg+sp1) = *(pImg+sp2);
|
|
209
211
|
sp1++;
|
|
210
212
|
sp2++;
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
|
-
break;
|
|
215
216
|
}
|
|
216
217
|
|
|
217
|
-
printf("完了");
|
|
218
|
-
|
|
219
218
|
//画像データ部を書き込む
|
|
220
219
|
fwrite(pChangeImg,sizeof(BYTE),iSize ,fp);
|
|
221
220
|
|
|
222
|
-
printf("完了");
|
|
223
|
-
|
|
224
221
|
//ファイルを閉じる
|
|
225
222
|
fclose(fp);
|
|
226
|
-
printf("完了");
|
|
227
223
|
}
|
|
228
224
|
|
|
225
|
+
|
|
229
226
|
```
|