复制BMP图片
| #include <stdio.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <sys/mman.h> |
| #include <stdlib.h> |
| |
| |
| |
| |
| |
| #pragma pack(1) |
| |
| |
| typedef struct |
| { |
| unsigned short bfType; |
| unsigned int bfSize; |
| unsigned short bfReserved1; |
| unsigned short bfReserved2; |
| unsigned int bfOffBits; |
| } BITMAPFILEHEADER; |
| |
| typedef struct |
| { |
| unsigned int biSize; |
| int biWidth; |
| int biHeight; |
| unsigned short biPlanes; |
| unsigned short biBitCount; |
| unsigned int biCompression; |
| unsigned int biSizeImage; |
| int biXPelsPerMeter; |
| int biYPelsPerMeter; |
| unsigned int biClrUsed; |
| unsigned int biClrImportant; |
| } BITMAPINFOHEADER; |
| |
| #pragma pack() |
| |
| int main(int argc, char const *argv[]) |
| { |
| |
| FILE *bmp_fp = fopen("1.bmp", "rb"); |
| if (NULL == bmp_fp) |
| { |
| return -1; |
| } |
| |
| BITMAPFILEHEADER h1; |
| BITMAPINFOHEADER h2; |
| |
| fread(&h1, 1, 14, bmp_fp); |
| fread(&h2, 1, 40, bmp_fp); |
| |
| |
| int line_size = h2.biWidth * 3; |
| char *src_pbuf = (char *)calloc(1, line_size); |
| |
| |
| FILE *new_fp = fopen("new.bmp", "wb"); |
| |
| fwrite(&h1, 1, 14, new_fp); |
| fwrite(&h2, 1, 40, new_fp); |
| |
| |
| int line_num = h2.biHeight; |
| while (line_num--) |
| { |
| |
| fread(src_pbuf, 1, line_size, bmp_fp); |
| |
| fwrite(src_pbuf, 1, line_size, new_fp); |
| } |
| |
| return 0; |
| } |
BMP图片显示到显示器
| #include <stdio.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <fcntl.h> |
| #include <unistd.h> |
| #include <sys/mman.h> |
| |
| |
| |
| |
| |
| #pragma pack(1) |
| |
| |
| typedef struct{ |
| unsigned short bfType; |
| unsigned int bfSize; |
| unsigned short bfReserved1; |
| unsigned short bfReserved2; |
| unsigned int bfOffBits; |
| }BITMAPFILEHEADER; |
| |
| typedef struct{ |
| unsigned int biSize; |
| int biWidth; |
| int biHeight; |
| unsigned short biPlanes; |
| unsigned short biBitCount; |
| unsigned int biCompression; |
| unsigned int biSizeImage; |
| int biXPelsPerMeter; |
| int biYPelsPerMeter; |
| unsigned int biClrUsed; |
| unsigned int biClrImportant; |
| }BITMAPINFOHEADER; |
| |
| |
| #pragma pack() |
| |
| |
| int main(int argc, char const *argv[]) |
| { |
| |
| FILE * bmp_fp = fopen("1.bmp","rb"); |
| if (NULL == bmp_fp) |
| { |
| return -1; |
| } |
| |
| |
| BITMAPINFOHEADER headerinfo; |
| fseek(bmp_fp,14,SEEK_SET); |
| fread(&headerinfo,1,40,bmp_fp); |
| printf("bmp width = %d,height = %d\n",headerinfo.biWidth,headerinfo.biHeight); |
| |
| |
| char bmp_buf[400*240*3] = {0}; |
| fread(bmp_buf,1,400*240*3,bmp_fp); |
| |
| |
| fclose(bmp_fp); |
| |
| |
| int lcd_fd = open("/dev/fb0",O_RDWR); |
| |
| |
| |
| int * lcd_mp = (int *)mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0); |
| |
| |
| int i = 0; |
| int data = 0; |
| |
| for (int y = 240-1; y >= 0; y--) |
| { |
| for (int x = 0; x < 400 ; ++x) |
| { |
| |
| data |= bmp_buf[i]; |
| data |= bmp_buf[i+1]<<8; |
| data |= bmp_buf[i+2]<<16; |
| |
| lcd_mp[800*y + x] = data; |
| |
| i+=3; |
| data = 0; |
| } |
| } |
| |
| |
| close(lcd_fd); |
| munmap(lcd_mp,400*240*4); |
| |
| return 0; |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具