그래서 이탈리아어 플래그 이미지 (왼쪽에서 오른쪽, 녹색, 흰색, 빨간색 순으로 3 개의 세로 막대)를 제공하는 ppm 파일을 만들어야합니다. 그리고 이미지는 600 x 400이어야합니다. (행별) 저는 코드를 여러 번 다시 작성하려고 시도했지만, 이미지는 수직이 아닌 가로로 배치 된 세 개의 막대 일뿐입니다. 또한 라인이 완전히 수평이 아닙니다. 하지만 가장 큰 문제는 내 녹색, 흰색 및 빨간색 막대가 왜 수직이 아닌지입니다. 어떤 도움이라도 대단히 감사합니다.내 이미지가 어떻게 보이겠습니까?
#include <stdio.h>
int main() {
printf("P6\n");
printf("%d %d\n", 600, 400);
printf("255\n");
int height, widthGreen, widthWhite, widthRed, i, j;
unsigned char Rcolor, Bcolor, Gcolor;
widthGreen = 200;
widthWhite = 400;
widthRed = 600;
height = 400;
for (j = 0; j < height; j++) {
for (i = 0; i < widthGreen; i++) {
Rcolor = 0;
Gcolor = 128;
Bcolor = 0;
printf("%c%c%c", Rcolor, Gcolor, Bcolor);
}
}
for (j = 0; j < height; j++) {
for (i = 201; i <= widthWhite; i++) {
Rcolor = 255;
Gcolor = 255;
Bcolor = 255;
printf("%c%c%c", Rcolor, Gcolor, Bcolor);
}
}
for (j = 0; j < height; j++) {
for (i = 401; i <= widthRed; i++) {
Rcolor = 255;
Gcolor = 0;
Bcolor = 0;
printf("%c%c%c", Rcolor, Gcolor, Bcolor);
}
}
return (0);
}
가능한 복제본 [왜 내 ppm 파일의 이미지가 약간 벗어 납니까?] (http://stackoverflow.com/questions/19651249/why-is-my-image-from-my-ppm-file) -a-little-off) – shodanex