#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
FILE* fp = fopen("R-C.bmp","r");
fseek(fp,2,SEEK_SET);
int bmp_size = 0;
fread(&bmp_size,4,1,fp);
printf("文件大小为 %d 字节\n",bmp_size);
int w = 0,h = 0;
fseek(fp,18,SEEK_SET);
fread(&w,4,1,fp);
fread(&h,4,1,fp);
printf("图像尺寸为:%d * %d\n",w,h);
fclose(fp);
fp = fopen("R-C.bmp","r+");
fseek(fp,54,SEEK_SET);
// bmp 图片默认像素格式是 bgr的
unsigned char pix1[3] = {0,255,255};
for(int i=0;i<w;i++)
{
for(int j=0;j<h/3;j++)
{
fwrite(pix1,3,1,fp);
}
}
unsigned char pix2[3] = {0,0,255};
for(int i=0;i<w;i++)
{
for(int j=0;j<h/3;j++)
{
fwrite(pix2,3,1,fp);
}
}
unsigned char pix3[3] = {0,0,0};
for(int i=0;i<w;i++)
{
for(int j=0;j<h/3;j++)
{
fwrite(pix3,3,1,fp);
}
}
fclose(fp);
return 0;
}
#include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #include <termios.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <assert.h>
8
9 int getch()
10 {
11 int c=0;
12 struct termios org_opts, new_opts;
13 int res=0;
14 res=tcgetattr(STDIN_FILENO, &org_opts);
15 assert(res==0);
16
17 new_opts = org_opts;
18
19 new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
20 tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
21
22 c=getchar();
23
24 res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
25 assert(res==0);
26 return c;
27 }
28
29 int main(int argc, char *argv[])
30 {
31 char c;
32 char arr[8]={0};
33 int i=0;
34 for(i=0;arr[i-1]!='\n'&&i<8;i++)
35 {
36 c=getch();
37 arr[i]=c;
38 printf("*");
39 }
40 putchar(10);
41 puts(arr);
42 return 0;
43 }