FFmpeg RGB数据添加BMP头

来源:互联网 发布:淘宝客服兼职 招聘吗 编辑:程序博客网 时间:2024/06/07 06:23
void RGB2BMP(AVFrame *pFrameRGB, int width, int height, int index, int bpp){    char buf[5] = {0};    BITMAPFILEHEADER bmpheader;    BITMAPINFOHEADER bmpinfo;    FILE *fp;    BITMAP B;    char *filename = new char[255];    //文件存放路径,根据自己的修改    sprintf_s(filename, 255, "%s%d.bmp", "D:/IMG/BMP/", index);    if( (fp = fopen(filename,"wb+")) == NULL ) {        printf ("open file failed!\n");        return;    }    bmpheader.bfType = 0x4d42;    bmpheader.bfReserved1 = 0;    bmpheader.bfReserved2 = 0;    bmpheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);    bmpheader.bfSize = bmpheader.bfOffBits + width*height*bpp/8;    bmpinfo.biSize = sizeof(BITMAPINFOHEADER);    bmpinfo.biWidth = width;    bmpinfo.biHeight = -height;//图片是正的    bmpinfo.biPlanes = 1;    bmpinfo.biBitCount = bpp;    bmpinfo.biCompression = BI_RGB;    bmpinfo.biSizeImage = (width*bpp+31)/32*4*height;    bmpinfo.biXPelsPerMeter = 100;    bmpinfo.biYPelsPerMeter = 100;    bmpinfo.biClrUsed = 0;    bmpinfo.biClrImportant = 0;    fwrite(&bmpheader, sizeof(bmpheader), 1, fp);    fwrite(&bmpinfo, sizeof(bmpinfo), 1, fp);    fwrite(pFrameRGB->data[0], width*height*bpp/8, 1, fp);    fclose(fp);}

原创粉丝点击