学习嵌入式的第22天

 寻找一个bmp图片,输出这张bmp图片第一个像素点和最后一个像素点的bgr的值

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>

typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
int main(int argc, char const *argv[])
{
    FILE* fp=fopen("/mnt/hgfs/Linux_share/rising_freedom/rising_freedom.bmp","r+");
	int bmp_w=0,bmp_h=0;
	fseek(fp,18,SEEK_SET);
	fread(&bmp_w,4,1,fp);
	fread(&bmp_h,4,1,fp);
    fseek(fp, 54, SEEK_SET);
    // 读取第一个像素点(注意BMP是BGR顺序)
    unsigned char bgr[3];
    fread(bgr, 1, 3, fp);
    printf("First pixel BGR: %u, %u, %u\n", bgr[0], bgr[1], bgr[2]);

    // 计算最后一个像素点的位置
    fseek(fp, 54 + (bmp_w * 3 * (bmp_h - 1)) + (bmp_w * 3 - 3), SEEK_SET);

    // 读取最后一个像素点
    fread(bgr, 1, 3, fp);
    printf("Last pixel BGR: %u, %u, %u\n", bgr[0], bgr[1], bgr[2]);
    return 0;
}

 修改一张bmp图片的大小,让他的宽度*2,高度*2,也就是最终像素点的数量*4,最后使用黑色像素点填充图片扩大的部分(不要求效果,只要求代码)

#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
#include <stdio.h>

typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;

int main(void)
{
    FILE *fp=fopen("/mnt/hgfs/Linux_share/rising_freedom/rising_freedom.bmp","r+");
	int bmp_w=0,bmp_h=0;
	fseek(fp,18,SEEK_SET);
	fread(&bmp_w,4,1,fp);
	fread(&bmp_h,4,1,fp);
    int a=bmp_w*2;
	int b=bmp_h*2;
    fseek(fp,18,SEEK_SET);
	fwrite(&a,4,1,fp);
	fwrite(&b,4,1,fp);
	unsigned char bgr[3]={0,0,0};
	fseek(fp,54,SEEK_SET);
	for(int i=0;i<bmp_h;i++)
	{   
        
		for(int j=bmp_w;j<a;j++)
		{
		fwrite(bgr,3,1,fp);
		}
	}
    for (int i= bmp_h; i < b; i++)
    {
        for(int j=0;j<a;j++)
		{
		fwrite(bgr,3,1,fp);
		}
    }
    
    fclose(fp);
    return 0;
}

将一张bmp图片修改成德国的国旗(如下图)

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>

typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;

int main(int argc, char const *argv[])
{
    FILE *fp = fopen("/mnt/hgfs/Linux_share/rising_freedom/rising_freedom.bmp", "r+");
    fseek(fp,18,SEEK_SET);
    int bmp_w=0,bmp_h=0;
	fread(&bmp_w,4,1,fp);
	fread(&bmp_h,4,1,fp);
    int b = bmp_h/3;
    unsigned char bgr[3]={0,0,0};
	fseek(fp,54,SEEK_SET);
	for(int i=0;i<b;i++)
	{
		for(int j=0;j<bmp_w;j++)
		{
		fwrite(bgr,3,1,fp);
		}
	}
     unsigned char bgr1[3]={0,0,255};

	for(int i=b;i<b*2;i++)
	{
		for(int j=0;j<bmp_w;j++)
		{
		fwrite(bgr1,3,1,fp);
		}
	}
    unsigned char bgr2[3]={255,255,0};
	
	for(int i=b*2;i<bmp_h;i++)
	{
		for(int j=0;j<bmp_w;j++)
		{
		fwrite(bgr2,3,1,fp);
		}
	}
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
第十二届蓝桥杯嵌入式竞赛是中国著名的计算机竞赛之一,也是我国嵌入式技术领域的重要比赛。本次比赛分为个人赛和团体赛两个部分,旨在提高参赛选手在嵌入式技术领域的创新能力和实践能力。 参赛选手需要通过开发具有特定功能的嵌入式系统来完成比赛任务。这不仅要求选手具备扎实的嵌入式技术知识,还需要灵活运用所学的理论知识,具备良好的实践能力和创新意识。 比赛的题目设计涵盖了嵌入式系统的各个方面,如硬件设计、软件开发、通信协议等。选手需要根据比赛的要求进行嵌入式系统的设计和开发,同时考虑系统的性能、功耗、可靠性等因素,以及解决实际问题的能力。 参与蓝桥杯嵌入式竞赛不仅可以让选手通过实践提升嵌入式技术能力,还能锻炼选手的综合能力和团队合作精神。在比赛中,选手不仅要独立完成任务,还需要与队友密切配合,共同克服各种困难和挑战。 此外,蓝桥杯嵌入式竞赛还为参赛选手提供了一个与业界专家进行交流和学习的机会。在比赛过程中,选手可以与专业人士交流经验,了解行业最新动态,提高自身的专业能力和综合素质。 总之,蓝桥杯嵌入式竞赛是一个很好的展示和提升嵌入式技术能力的平台。通过参与比赛,选手可以提高自己的实践技能、创新能力和解决问题的能力,为未来在嵌入式领域的发展奠定坚实基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值