Android C++ service层 抓Camera RGB流并保存为bmp放在特定路径下

1. 整个for循环抓流保存BMP

for(int i=0; i     {   
        const char* filename = NULL;
        string tmpf1 = "/sdcard/bmp/";
        string tmpf2 = std::to_string(i+1);
        string tmpf3 = ".bmp";
        string tmpf = tmpf1 + tmpf2 + tmpf3;
        filename = tmpf.c_str();
        usleep(500000);  
        // this position is RBG streaming
        savebmp((unsigned char *)(rgb), filename, yuvwidth, yuvheight);
        }

 

2. RGB保存bmp相关:参考的《https://blog.csdn.net/yixianfeng41/article/details/52591585》,如果博主不允许,我将扯下去,谢谢。实现部分稍作修改,才跑通

2.1 BMP文件头(14字节)

typedef struct
{
    unsigned int   bfSize;
    unsigned short bfReserved1;
    unsigned short bfReserved2;
    unsigned int   bfOffBits;
} MyBITMAPFILEHEADER;

2.2 位图信息头(40字节)
typedef struct
{
    unsigned int   biSize;
    int            biWidth;
    int            biHeight;
    unsigned short biPlanes;
    unsigned short biBitCount;
    unsigned int   biCompression;
    unsigned int   biSizeImage;
    int            biXPelsPerMeter;
    int            biYPelsPerMeter;
    unsigned int   biClrUsed;
    unsigned int   biClrImportant;
} MyBITMAPINFOHEADER;

 

2.3 具体方法:(相对原文章修改的部分,参见下面粗体字)

void xxxxx::savebmp(unsigned char *rgbbuf,const char *filename,int width,int height)
{
    MyBITMAPFILEHEADER bfh;
    MyBITMAPINFOHEADER bih;
    unsigned short bfType=0x4d42;
    bfh.bfReserved1=0;
    bfh.bfReserved2=0;
    bfh.bfSize=2+sizeof(MyBITMAPFILEHEADER)+sizeof(MyBITMAPINFOHEADER)+width*height*3;
    bfh.bfOffBits=0x36;
    bih.biSize=sizeof(MyBITMAPINFOHEADER);
    bih.biWidth=width;
    bih.biHeight=height;
    bih.biPlanes=1;
    bih.biBitCount=24;
    bih.biCompression=0;
    bih.biSizeImage=0;
    bih.biXPelsPerMeter=5000;
    bih.biYPelsPerMeter=5000;
    bih.biClrUsed=0;
    bih.biClrImportant=0;
    FILE *file=fopen(filename,"wb");
    if(!file)
    {
        printf("Could not write file\n");
        return;
    }
    fwrite(&bfType,sizeof(bfType),1,file);
    fwrite(&bfh,sizeof(bfh),1,file);
    fwrite(&bih,sizeof(bih),1,file);
    fwrite(rgbbuf,width*height*3,1,file);
    fclose(file);
}

 

你可能感兴趣的:(Android C++ service层 抓Camera RGB流并保存为bmp放在特定路径下)