linux开发板截图程序

今天因为工作需要,要截取开发板屏幕上面的图片,在网上找了几个可能是由于个人操作原因,都失败了,没办法自己想想吧,其实很简单,就是让屏幕显示的逆操作!

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <asm/types.h> 
#include <linux/videodev2.h>
#include <linux/fb.h>


static unsigned int capframe = 0;
static unsigned char filename[30];
FILE *bmpFile;

unsigned char bmp_head_t[] = {
        0x42,0x4d,0x42,0x58,0x02,0x00,0x00,0x00,0x00,0x00,
        0x42,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0xf0,0x00,
        0x00,0x00,0x40,0x01,0x00,0x00,0x01,0x00,0x10,0x00,
        0x03,0x00,0x00,0x00,0x00,0x58,0x02,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0xe0,0x07,
        0x00,0x00,0x1f,0x00,0x00,0x00
};


static int fb_bpp;
unsigned char bmp_head[54];

static int fb_fp = -1;
static char *fb_addr = NULL;

int width=0;
int height=0;

static inline int fb_init(void)
{
	int dev_fp = -1;
	int fb_size;
	struct fb_var_screeninfo vinfo;

	dev_fp = open("/dev/fb0", O_RDWR);
	if (dev_fp < 0) {
		perror("/dev/fb0");
		return -1;
	}
	if (ioctl(dev_fp, FBIOGET_VSCREENINFO, &vinfo)) {
	        printf("Error reading variable information.\n");
		exit(1);
	}
	width=vinfo.xres;
	height=vinfo.yres;
	fb_bpp=vinfo.bits_per_pixel;
	if(fb_bpp==24) fb_bpp=32;
	fb_size=width*height*fb_bpp/8;
	if ((fb_addr = (char*)mmap(0, fb_size, 
			PROT_READ | PROT_WRITE, MAP_SHARED, dev_fp, 0)) < 0) {
		perror("mmap()");
		return -1;
	}
	printf("%dx%d bpp:%d mmaped 0x%08x\n",width,height,fb_bpp,fb_addr);

	return dev_fp;
}

void writeImageToFile(unsigned int size)
{
	capframe++;
	sprintf(filename,"/test/0%d.bmp",capframe);
   	bmpFile=fopen(filename, "w+");
	if(fb_bpp == 16)
		fwrite(bmp_head_t,1,66,bmpFile);
	else
		fwrite(bmp_head,1,54,bmpFile);
   	fwrite(fb_addr,1,size,bmpFile);
   	fclose(bmpFile);
}

int main(int argc, char *argv[])
{
	unsigned int i = 10;
	unsigned long size = 0;
	fb_fp = fb_init();	
	size=width*height*fb_bpp/8;

	if(fb_bpp==16){
	    *((unsigned int*)(bmp_head_t+18)) = width;
	    *((unsigned int*)(bmp_head_t+22)) = height;
	    *((unsigned short*)(bmp_head+28)) = 16;
	}else{
	bmp_head[0] = 'B';
	bmp_head[1] = 'M';
	*((unsigned int*)(bmp_head+2)) = (width*fb_bpp/8)*height+54;
	*((unsigned int*)(bmp_head+10)) = 54;
	*((unsigned int*)(bmp_head+14)) = 40;
	*((unsigned int*)(bmp_head+18)) = width;
	*((unsigned int*)(bmp_head+22)) = height;
	*((unsigned short*)(bmp_head+26)) = 1;
	*((unsigned short*)(bmp_head+28)) = fb_bpp;
	*((unsigned short*)(bmp_head+34)) = (width*fb_bpp/8)*height;
	}

	while(i--)
	{
		
		writeImageToFile(size);

	}
	 

	return 0;
}


linux开发板上进行ftp批量程序升级,可以通过以下步骤实现: 1. 首先,确保linux开发板已经正确连接到网络,并且可以通过FTP协议进行通信。 2. 在开发板上安装FTP服务器软件。可以选择常用的FTP服务器软件如vsftpd、proftpd等。通过包管理器安装服务器软件,并根据需求进行相应的配置。 3. 在FTP服务器上创建一个用于批量程序升级的目录,并设置相应的权限,确保目录中的程序文件可以被访问和下载。 4. 将需要升级的程序文件上传到FTP服务器的批量升级目录中。可以使用FTP客户端工具,比如FileZilla等,通过FTP协议将程序文件上传到指定目录。 5. 在linux开发板上的终端中,使用FTP客户端工具连接到FTP服务器。可以使用命令行工具如ftp或lftp,在终端中输入相关命令进行连接。 6. 登录成功后,使用FTP客户端工具浏览批量升级目录,找到需要升级的程序文件,并下载到开发板上。 7. 在开发板上执行程序升级操作。根据具体的程序升级方法,可以使用命令行工具如scp、wget等,或者通过脚本等自动化方式进行程序升级。 8. 针对批量升级操作,可以编写脚本或者使用循环结构,自动化地依次升级多个程序文件。 9. 确保程序升级过程中的稳定性和安全性,可以进行相关的测试和验证。 通过上述步骤,就可以在linux开发板上使用FTP协议进行批量程序升级了。这样可以简化程序升级过程,提高效率,并确保升级操作的准确性。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值