马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在屏幕上显示图像,屏幕,尺寸为1024*600,位深为2- /**************************************************************************
- *
- *
- * 设计在屏幕指定位置显示图像的接口
- * author:jindouliu2024@163.com
- * date:2025.4.18
- *
- *
- * Copyright (c) 2024-2025 jindouliu2024@163.com All right Reserved
- * *************************************************************************/
复制代码 [code]#include #include #include #include #include #include#include#include#include#include #pragma pack(1)typedef struct tagBITMAP_FILE_HEADER{ short bfType;//文件标识 int bfSize;//文件大小 short bfReserved1;//保存字 short bfReserved2;//保存字 int bfOffBits;//文件指示器偏移量相较于文件开头} bpFile_Header, *PbpFile_Header;typedef struct tagBITMAPINFOHEADER{ int bpSize;//图像描述信息块的大小 int bpWidth;//图像宽度 int bpHeight;//图像高度 short bpPlanes;//图像的plane总数(恒为1) short bpBitCount;//记录颜色的位数取值1(双色),4,6,24,32 int bpCompression;//数据压缩方式(0:不压缩;1:8位压缩;2:4位压缩) int bpSizeImage;//图像区数据的大小,必须是4的倍数 int bpXPelsPerMeter;//水平每米有多少像素,在设备无关位图中,填写00H int bpYPelsPerMeter;//垂直每米有多少像素,在设备无关位图中,填写00H int bpClrUsed;// 此图像所有的颜色数,不消,固定为0 int bpClrImportant;// 重要颜色数,不消,固定为0} bpINFO_HEADER, *PbpINFO_HEADER;#pragma pack()bool ShowPicture(char *name,int x,int y)//{ int i=0; short data=0; int cnt=0; //定义存储图像信息的结构体 bpINFO_HEADER bp_infoheader; //打开图像文件 FILE *fp = fopen(name,"rb"); if(fp == NULL){ printf("open picture failed\n "); return -1; } //读取文件头信息 fseek(fp,14,SEEK_SET); fread(&bp_infoheader,1,40,fp); //定义存储数据的数组 char info_buf[bp_infoheader.bpWidth*bp_infoheader.bpHeight*3]; //读取图像信息 fread(info_buf,1,bp_infoheader.bpWidth*bp_infoheader.bpHeight*3,fp); printf("width = %d,heigth =%d",bp_infoheader.bpWidth,bp_infoheader.bpHeight); //关闭图像文件 fclose(fp); //打开屏幕文件 int lcd_dp = open("/dev/fb0",O_RDWR); //将图像信息写入mmap //申请mmap的空间 short *lcd_mp = (short *)mmap(NULL,1024*600*2,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_dp,0); //计算需要补齐的字节数目 cnt = ((4-(bp_infoheader.bpWidth*24/8)%4)%4); //按高度扫描 for(int k = x+bp_infoheader.bpHeight-1;k >= x ;k--){ //按宽度扫描 for(int z = y;z < y+bp_infoheader.bpWidth;z++){ //写入像素值 data = (info_buf/8)|((info_buf[i+1]/4)
|