私は .ppm ファイルに書き込んでいます。これまでのところ、0 と 1 を書き込んでテストしています。メモ帳でファイルを開くと、数字が記号として表示されます。しかし、ワードパッドまたは Microsoft Word で開くと、数字が表示されます。確かにコードに問題はなく、それはメモ帳のせいですか? Google経由で調べようとしましたが、何も見つかりません。基本的に、私がやっていることは、(1 1 1 1) から (1 0 0 1 0 0 1 0 0 1 0 0) のような値を含むファイルを展開することです。これは赤いピクセルであり、次に緑と青の値を追加します同じように。
100100100100 の代わりに ‱‰‱‰‰ ‱‰‰ ‱‰‰ を取得します。
コードは次のとおりです。
#include <stdio.h>
int redArray[128][256 * 3];
int main(void) {
int x;
int y;
FILE *redFile = NULL;
imagePixels = fopen("image.ppm", "w");
redFile = fopen("image.red", "r");
readRed(redFile);
for (y = 0; y < 128; y++) {
for (x = 0; x < 256 * 3; x += 3) {
redArray[y][x] = 1;
}
}
for (y = 0; y < 1; y++) {
for (x = 0; x < 256 * 3; x++) {
fprintf(imagePixels, "%d ", redArray[y][x]);
}
}
fclose(redFile);
fclose(imagePixels);
return 0;
}
// This function is in a different .c file. I completely forgot to add it here but I'll leave at the '#include' business.
void readRed(FILE *colourFile) {
for (y = 0; y < 128; y++) {
for (x = 0; x < 256; x++) {
fscanf(redFile, "%d", &redArray[y][x]);
}
}
}