void CffmpegUIDlg::SaveAsBMP(AVFrame *pFrameRGB, int width, int height, int index, int bpp)
{
BITMAPFILEHEADER bmpheader;
BITMAPINFOHEADER bmpinfo;
bmpheader.bfType = 0x4d42;
bmpheader.bfReserved1 = ;
bmpheader.bfReserved2 = ;
bmpheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmpheader.bfSize = bmpheader.bfOffBits + width\*height\*bpp / ;
bmpinfo.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.biWidth = width;
bmpinfo.biHeight = height;
bmpinfo.biPlanes = ;
bmpinfo.biBitCount = bpp;
bmpinfo.biCompression = BI\_RGB;
bmpinfo.biSizeImage = (width\*bpp + ) / \* \* height;
bmpinfo.biXPelsPerMeter = ;
bmpinfo.biYPelsPerMeter = ;
bmpinfo.biClrUsed = ;
bmpinfo.biClrImportant = ;
DWORD dwInfoSize = width\*height\*bpp / ;
HGLOBAL hGlobal = GlobalAlloc( GMEM\_MOVEABLE, sizeof(bmpheader) + sizeof(bmpinfo) + dwInfoSize);
BYTE \*pvData = (BYTE\*)GlobalLock( hGlobal );
memcpy(pvData, &bmpheader, sizeof(bmpheader));
memcpy(pvData + sizeof(bmpheader), &bmpinfo, sizeof(bmpinfo));
memcpy(pvData + sizeof(bmpheader) + sizeof(bmpinfo), pFrameRGB->data\[\], dwInfoSize);
GlobalUnlock( hGlobal );
Gdiplus::Graphics graphics(hdcClient);
IStream \*pStream = NULL;
HRESULT hr = CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );
Gdiplus::Bitmap bmp(pStream);
graphics.DrawImage(&bmp, , );
GlobalFree( hGlobal ); // 使用Bitmap完后,需要释放资源,以免造成内存泄漏。
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章