实现屏幕的九分屏
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
//像素为1280*800
int main ()
{
int fd = open("/dev/fb0", O_RDWR);
if(fd < 0)
{
perror("error open \n");
return -1;
}
int i = 0;
int arr[426] ;
int brr[426] ;
int crr[428] ;
for(i = 0; i < 426; i++)
{
arr[i] = 0xff00ff;
}
for(i = 0; i < 426; i++)
{
brr[i] = 0xffff00;
}
for(i = 0; i < 428 ; i++)
{
crr[i] = 0x0000ff;
}
int a = 266;
while(a--)
{
write(fd, arr, 426*4);
write(fd, brr, 426*4);
write(fd, crr, 428*4);
}
int b = 532;
while(b--)
{
write(fd, brr, 426*4);
write(fd, crr, 428*4);
write(fd, arr, 426*4);
if(b == 266 )
{
break;
}
}
int c = 800;
while(c--)
{
write(fd, crr, 428*4);
write(fd, arr, 426*4);
write(fd, brr, 426*4);
if(b == 532 )
{
break;
}
}
close(fd);
return 0;
}
显示BMP图片
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
//查看像素
//变换工具->旋转and缩放->高级选项
//用ls -l 查看图片大小
//aa *2 70
//aa1 *2 70
//aa2 *2 54
//aa3 *3 54 dui
//aa4 *2 70
//aa5 *4 70 d
int main ()
{
int fd = open("/dev/fb0", O_RDWR);
if(fd < 0)
{
perror("error open \n");
return -1;
}
int fd1 = open("aa3.bmp", O_RDONLY);
lseek(fd1, 54, SEEK_SET);
unsigned int *p = mmap(NULL, 1280*800*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if(p == NULL)
{
perror("error open \n");
return -1;
}
int i = 0;
for(i = 0; i < 1280*800*4; i++)
{
read(fd1, (p+i), 3);
}
munmap(p, 1280*800*4);
close(fd1);
close(fd);
return 0;
}
计算图片的相关操作:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
// vga=788 800*600 RGB565
// bfType 2字节
// bfSize 4字节
// bfReserved1/2 4字节
// bfOffBits 4Byte
#pragma pack(1)
struct header{
unsigned short bfType;
unsigned int bfSize;
unsigned int bfReserved;
unsigned int bfOffBits;
};
int main()
{
int fd1 = open("1.bmp", O_RDONLY );
struct header h1;
read( fd1, &h1, sizeof(h1) );
printf("0x%x\n", h1.bfType );
printf("%d\n", h1.bfSize );
printf("0x%x\n", h1.bfReserved );
printf("0x%x\n", h1.bfOffBits );
return 0;
}