2024.8.6

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.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, const char *argv[])
{
    FILE* fp=fopen("./rising_freedom.bmp","r");
    int bmp_size=0,bmp_W=0,bmp_W0=0,bmp_h0=0,bmp_h=0,bmp_fh=0,bmp_fz=0,bmpss=0;
    fseek(fp,2,SEEK_SET);
    fread(&bmp_size,4,1,fp);
    fseek(fp,18,SEEK_SET);
    fread(&bmp_W,4,1,fp);
    fread(&bmp_h,4,1,fp);
    fseek(fp,38,SEEK_SET);
    fread(&bmp_fh,4,1,fp);
    fseek(fp,42,SEEK_SET);
    fread(&bmp_fz,4,1,fp);
    fseek(fp,42,SEEK_SET);
    fread(&bmpss,4,1,fp);
    fclose(fp);
    fp=fopen("./rising_freedom.bmp","r+");
    int arr[2]={2*bmp_W,2*bmp_h};
    int arr2[2]={2*bmp_fh,2*bmp_fz};
    int arr3[1]={4*bmpss};
    fseek(fp,18,SEEK_SET);//宽度
    fwrite(arr,4,1,fp);
    fread(&bmp_W0,4,1,fp);
    fseek(fp,22,SEEK_SET);//高度
    fwrite(arr,4,1,fp);
    fread(&bmp_h0,4,1,fp);
    fseek(fp,38,SEEK_SET);//像素宽度
    fwrite(arr2,4,1,fp);
    fseek(fp,42,SEEK_SET);//像素高度
    fwrite(arr2,4,1,fp);
    fseek(fp,26,SEEK_SET);
    fwrite(arr3,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<bmp_W0;j++)
        {
            fwrite(bgr,3,1,fp);    
        }
    }
    for(int i=bmp_h;i<bmp_h0;i++)
    {
        for(int j=0;j<bmp_W0;j++)
        {
            fwrite(bgr,3,1,fp);
        }
    }
    fclose(fp);

//    unsigned char bgr[3]={0,0,0};
//    fseek(fp,54,SEEK_SET);
//    for(int i=0;i<bmp_h;i++)
//    {
//        for(int j=0;j<(bmp_W);j++)
//        {
//            fread(bgr,3,1,fp);
//            if(i==0&&j==0)
//            {
//                printf("%d %d %d \n",bgr[0],bgr[1],bgr[2]);
//            }
//            if(i==bmp_h-1&&j==bmp_W-1)
//            {
//                printf("%d %d %d \n",bgr[0],bgr[1],bgr[2]);
//            }
//        }
//    }
//    fclose(fp);


//    unsigned char bgr[3]={0,0,255};
//    unsigned char bgr2[3]={0,0,0};
//    unsigned char bgr3[3]={63,143,204};
//    fseek(fp,54,SEEK_SET);
//    for(int i=0;i<(bmp_h/3);i++)
//    {
//        for(int j=0;j<(bmp_W);j++)
//        {
//            fwrite(bgr3,3,1,fp);
//        }
//    }
//    for(int i=(bmp_h/3);i<(bmp_h/3)*2;i++)
//    {
//        for(int j=0;j<(bmp_W);j++)
//        {
//            fwrite(bgr,3,1,fp);
//        }
//    }
//    for(int i=(bmp_h/3)*2;i<bmp_h;i++)
//    {
//        for(int j=0;j<(bmp_W);j++)
//        {
//            fwrite(bgr2,3,1,fp);
//        }
//    }
//    fclose(fp);


    return 0;
}
 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.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, const char *argv[])
{
	FILE* fp=fopen("./rising_freedom.bmp","r");
	int bmp_size=0,bmp_W=0,bmp_W0=0,bmp_h0=0,bmp_h=0,bmp_fh=0,bmp_fz=0,bmpss=0;
	fseek(fp,2,SEEK_SET);
	fread(&bmp_size,4,1,fp);
	fseek(fp,18,SEEK_SET);
	fread(&bmp_W,4,1,fp);
	fread(&bmp_h,4,1,fp);
	fseek(fp,38,SEEK_SET);
	fread(&bmp_fh,4,1,fp);
	fseek(fp,42,SEEK_SET);
	fread(&bmp_fz,4,1,fp);
	fseek(fp,42,SEEK_SET);
	fread(&bmpss,4,1,fp);
	fclose(fp);
	fp=fopen("./rising_freedom.bmp","r+");
	int arr[2]={2*bmp_W,2*bmp_h};
	int arr2[2]={2*bmp_fh,2*bmp_fz};
	int arr3[1]={4*bmpss};
	fseek(fp,18,SEEK_SET);//宽度
	fwrite(arr,4,1,fp);
	fread(&bmp_W0,4,1,fp);
	fseek(fp,22,SEEK_SET);//高度
	fwrite(arr,4,1,fp);
	fread(&bmp_h0,4,1,fp);
	fseek(fp,38,SEEK_SET);//像素宽度
	fwrite(arr2,4,1,fp);
	fseek(fp,42,SEEK_SET);//像素高度
	fwrite(arr2,4,1,fp);
	fseek(fp,26,SEEK_SET);
	fwrite(arr3,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<bmp_W0;j++)
		{
			fwrite(bgr,3,1,fp);	
		}
	}
	for(int i=bmp_h;i<bmp_h0;i++)
	{
		for(int j=0;j<bmp_W0;j++)
		{
			fwrite(bgr,3,1,fp);
		}
	}
	fclose(fp);





//	unsigned char bgr[3]={0,0,0};
//	fseek(fp,54,SEEK_SET);
//	for(int i=0;i<bmp_h;i++)
//	{
//		for(int j=0;j<(bmp_W);j++)
//		{
//			fread(bgr,3,1,fp);
//			if(i==0&&j==0)
//			{
//				printf("%d %d %d \n",bgr[0],bgr[1],bgr[2]);
//			}
//			if(i==bmp_h-1&&j==bmp_W-1)
//			{
//				printf("%d %d %d \n",bgr[0],bgr[1],bgr[2]);
//			}
//		}
//	}
//	fclose(fp);


//	unsigned char bgr[3]={0,0,255};
//	unsigned char bgr2[3]={0,0,0};
//	unsigned char bgr3[3]={63,143,204};
//	fseek(fp,54,SEEK_SET);
//	for(int i=0;i<(bmp_h/3);i++)
//	{
//		for(int j=0;j<(bmp_W);j++)
//		{
//			fwrite(bgr3,3,1,fp);
//		}
//	}
//	for(int i=(bmp_h/3);i<(bmp_h/3)*2;i++)
//	{
//		for(int j=0;j<(bmp_W);j++)
//		{
//			fwrite(bgr,3,1,fp);
//		}
//	}
//	for(int i=(bmp_h/3)*2;i<bmp_h;i++)
//	{
//		for(int j=0;j<(bmp_W);j++)
//		{
//			fwrite(bgr2,3,1,fp);
//		}
//	}
//	fclose(fp);


	return 0;
}

  • 18
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值