所以,我必须创建一个ppm文件,它会给我意大利国旗的图像(从左到右,绿色,白色,然后红色的顺序是3个垂直条)。图像必须是600×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,小关) – shodanex