linux 如何查看fb中分辨率_通用Linux截图(linuxfb方法)

知道树莓派啊这些他跑Raspbian时候是完整系统,如果他跑batocera之类的时候,他只是一个busybox,没有截图工具,做教程非常麻烦.

用这个代码,编译后,丢上去,随便哪里截图都行,出来bmp文件.不管你是嵌入式系统还是树莓派还是什么.

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

static unsigned char sg_BHeader[] =

{

0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,

0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00,

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x00, 0x00, 0x00, 0x00, 0x00

};

#define RGB565TO1555(rgb) ((unsigned short)((unsigned short)(rgb & 0x001f) | ((unsigned short)(rgb & 0xffc0) >> 1)))

void SaveBMPFile(unsigned char *raw, char *filename)

{

unsigned short *p = (unsigned short *)raw;

typedef unsigned int UINT;

typedef unsigned char UCHAR;

UINT m_Width = 480, m_Height = 272;

UINT i, j;

int bmp = open(filename, O_WRONLY | O_CREAT);

if(bmp < 0)

return;

sg_BHeader[0x02] = (UCHAR)(m_Width * m_Height * 2 + 0x36) & 0xff;

sg_BHeader[0x03] = (UCHAR)((m_Width * m_Height * 2 + 0x36) >> 8) & 0xff;

sg_BHeader[0x04] = (UCHAR)((m_Width * m_Height * 2 + 0x36) >> 16) & 0xff;

sg_BHeader[0x05] = (UCHAR)((m_Width * m_Height * 2 + 0x36) >> 24) & 0xff;

sg_BHeader[0x12] = (UCHAR)m_Width & 0xff;

sg_BHeader[0x13] = (UCHAR)(m_Width >> 8) & 0xff;

sg_BHeader[0x14] = (UCHAR)(m_Width >> 16) & 0xff;

sg_BHeader[0x15] = (UCHAR)(m_Width >> 24) & 0xff;

sg_BHeader[0x16] = (UCHAR)m_Height & 0xff;

sg_BHeader[0x17] = (UCHAR)(m_Height >> 8) & 0xff;

sg_BHeader[0x18] = (UCHAR)(m_Height >> 16) & 0xff;

sg_BHeader[0x19] = (UCHAR)(m_Height >> 24) & 0xff;

write(bmp, sg_BHeader, sizeof(sg_BHeader));

for(i = 0; i < m_Height; i++)

{

unsigned short *c = p + (m_Height - 1 - i) * m_Width;

unsigned short cc;

for(j = 0; j < m_Width; j++)

{

cc = RGB565TO1555(*(c + j));

//cc = *(c + j);

write(bmp, &cc, 2);

}

}

close(bmp);

}

int main(int argc, char *argv[])

{

unsigned char buf[480 * 272 * 2];

char *filename;

int fb;

fb = open("/dev/fb0", O_RDONLY);

if(fb < 0)

exit(1);

if(argc == 2)

filename = argv[1];

else

exit(1);

read(fb, buf, 480 * 272 * 2);

close(fb);

SaveBMPFile(buf, filename);

exit(0);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值