当前位置:   article > 正文

粤嵌GEC6818实现电子相册_粤嵌电子相册代码

粤嵌电子相册代码

1.打印触摸屏坐标数据

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <strings.h>
#include <linux/input.h>

void main()
{
	struct input_event myevent; //type:事件类型;code:事件代码;value:事件的值
	int x,y;
	//打开触摸屏设备文件
	int ts_fd;
	ts_fd = open("/dev/input/event0",O_RDONLY);
	//读取触摸屏数据
	while(1)
	{
		read(ts_fd,&myevent,sizeof(myevent));
		
		if(myevent.type==EV_ABS)
		{
			if(myevent.code==ABS_X)
			{
				x=myevent.value;
			}
			if(myevent.code==ABS_Y)
			{
				y=myevent.value;
			}
		}
		if(myevent.type==EV_KEY&&myevent.code==BTN_TOUCH&&myevent.value==0)
		{
			printf("%d %d\n",x,y);
		}
		
	}
	
	//打印触摸屏数据
	//printf("type=%d,code=%d,value=%d\n",myevent.type,myevent.code,myevent.value);
	
	close(ts_fd);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

2.相册(触摸换图)

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <sys/mman.h>
#include <linux/input.h>

int show(const char* path);//bmp图片显示函数原型

int main()
{
	int x,y,k=0;;
	char photo[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"};
	struct input_event myevent;//定义数据缓冲区
	
	//打开触摸屏设备文件
	int ts_fd = open("/dev/input/event0",O_RDONLY);
	
	while(1)
	{
		//读取数据并输出
		read(ts_fd,&myevent,sizeof(myevent)); //阻塞,等待输入
		if(myevent.type==EV_ABS)
		{
			if(myevent.code==ABS_X)
			{
				x=myevent.value;
			}
			if(myevent.code==ABS_Y)
			{
				y=myevent.value;
			}
		}
		if(myevent.type == EV_KEY && myevent.code == BTN_TOUCH && myevent.value == 0)
		{
			if(x<400)
			{
				k++;
				if(k==4)
				{
					k=0;
				}
				show(photo[k]);
			}
			
			if(x>400)
			{
				k--;
				if(k<0)
				{
					k=3;
				}
				show(photo[k]);
			}
		}
	}	
	//关闭触摸屏
	close(ts_fd);
	return 0;
}

//bmp图片显示函数实现
int show(const char* path)
{
	int x,y;
	int lcd_fd,bmp_fd;
	char bmp_buf[800*480*3];
	bzero(bmp_buf,sizeof(bmp_buf));
	int lcd_buf[800*480];
	bzero(lcd_buf,sizeof(lcd_buf));
	int show_buf[800*480];
	bzero(show_buf,sizeof(show_buf));
	
	//打开LCD设备文件
	lcd_fd = open("/dev/fb0",O_RDWR);
	
	//打开图片
	bmp_fd = open(PATH,O_RDONLY);
	
	//定位光标
	lseek(bmp_fd,54,SEEK_SET);
	
	//读图片像素
	read(bmp_fd,bmp_buf,sizeof(bmp_buf));
		
	for(int i=0;i<800*480; i++)
	{
		lcd_buf[i] = bmp_buf[i*3]<<0 | bmp_buf[i*3+1]<<8 | bmp_buf[i*3+2]<<16;
	}
	
	//解决图片颠倒问题
	for(y=0; y<480; y++)
	{
		for(x=0; x<800; x++)
		{
			show_buf[(479-y)*800+x] = lcd_buf[800*y+x];
		}
	}
	
	//内存映射
	int *fd_mmap = mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,lcd_fd,0);
	
	//显示
	for(int i=0;i<800*480;i++)
	{
		*(fd_mmap+i)=show_buf[i];
	}
	
	close(lcd_fd);//关闭LCD
	close(bmp_fd);//关闭图片文件
    munmap(fd_mmap,800*480*4);//解除内存映射

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116

3.相册翻页添加特效

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <strings.h>
#include <linux/input.h>
#include "show_bmp.h"

int show(const char picturenum);

void main()
{
	struct input_event myevent; //type,code,value
	int x,y;
	int k=0;
	//char picture[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"};

	//打开触摸屏设备文件
	int ts_fd;
	ts_fd = open("/dev/input/event0",O_RDONLY);
	
	//读取触摸屏数据
	while(1)
	{
		read(ts_fd,&myevent,sizeof(myevent));
		
		if(myevent.type==EV_ABS)
		{
			if(myevent.code==ABS_X)
			{
				x=myevent.value;
			}
			if(myevent.code==ABS_Y)
			{
				y=myevent.value;
			}
		}
		if(myevent.type==EV_KEY&&myevent.code==BTN_TOUCH&&myevent.value==0)
		{
			if(x>400)
			{
				k++;
				if(k>3){k=0;}
				show(k);
				
			}
			if(x<400)
			{
				k--;
				if(k<0){k=3;}
				show(k);
		
			}
		}
		
	}
	
	//打印触摸屏数据
	//printf("type=%d,code=%d,value=%d\n",myevent.type,myevent.code,myevent.value);
	
	close(ts_fd);
}

int show(const char picturenum)
{
	int p_fd;
	p_fd = open("/dev/fb0",O_RDWR);
	int *pfd_mmap = mmap(NULL,800*480*4,PROT_READ | PROT_WRITE,MAP_SHARED,p_fd,0);
	//char picture[][30]={"1.bmp","2.bmp","3.bmp","4.bmp"};
	
	if(picturenum==0)
	{
		pic_circular_spread("./1.bmp",pfd_mmap);
	}
	if(picturenum==1)
	{
		pic_down("./2.bmp",pfd_mmap);
	}
	if(picturenum==2)
	{
		pic_circular_shrink("./3.bmp",pfd_mmap);
	}
	if(picturenum==3)
	{
		pic_left("./4.bmp",pfd_mmap);
	}	
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/855489
推荐阅读
相关标签
  

闽ICP备14008679号